Macros for SAS Application Developers 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.



filename example temp;
data; infile example; input;put _infile_; if _n_>5 then stop;run;

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

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
[in]dsThe dataset to be exported
[in]dlm=(COMMA) The delimeter to apply. For SASJS, will always be COMMA. Supported values:
[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 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 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

Allan Bowe (credit mjsq)

Definition in file