mp_ds2csv.sas File Reference

Export a dataset to a CSV file WITH leading blanks. More...

Go to the source code of this file.

Detailed Description

Export a dataset to a file or fileref, retaining leading blanks.

When using SASJS headerformat, the input statement is provided in the first row of the CSV.

Usage:

%mp_ds2csv(sashelp.class,outref="%sysfunc(pathname(work))/file.csv")

filename example temp;
%mp_ds2csv(sashelp.air,outref=example,headerformat=SASJS)
data; infile example; input;put _infile_; if _n_>5 then stop;run;

data _null_;
  infile example;
  input;
  call symputx('stmnt',_infile_);
  stop;
run;
data work.want;
  infile example dsd firstobs=2;
  input &stmnt;
run;

Why use mp_ds2csv over, say, proc export?

  1. Ability to retain leading blanks (this is a major one)
  2. Control the header format
  3. Simple one-liner
Parameters
[in]dsThe dataset to be exported
[in]dlm=(COMMA) The delimeter to apply. For SASJS, will always be COMMA. Supported values:
  • COMMA
  • SEMICOLON
[in]headerformat=(LABEL) The format to use for the header section. Valid values:
  • LABEL - Use the variable label (or name, if blank)
  • NAME - Use the variable name
  • SASJS - Used to create sasjs-formatted input CSVs, eg for use in mp_testservice.sas. This format will supply an input statement in the first row, making ingestion by datastep a breeze. Special misisng values will be prefixed with a period (eg .A) to enable ingestion on both SAS 9 and Viya. Dates / Datetimes etc are identified by the format type (lookup with mcf_getfmttype.sas) and converted to human readable formats (not numbers).
[out]outfile=The output filename - should be quoted.
[out]outref=(0) The output fileref (takes precedence if provided)
[in]outencoding=(0) The (quoted) output encoding to use, eg "UTF-8"
[in]termstr=(CRLF) The line seperator to use. For SASJS, will always be CRLF. Valid values:
  • CRLF
  • LF

SAS Macros

Version
9.2
Author
Allan Bowe (credit mjsq)

Definition in file mp_ds2csv.sas.