Ken Kleinman

Biostatistician

  • Increase font size
  • Default font size
  • Decrease font size

Convert data to CSV file

E-mail Print PDF

In addition to the export file wizard and proc export (section 1.2.3 of SAS and R), SAS provides the nifty little %ds2csv macro that can do this quickly and easily. 

The advantages to this approach are that there are a few extra options and that the documentation is actually more explicit than that provided for proc export.

Example:

data test;
do i = 1 to 20;
x = normal(0);
y = ranpoi(0,10);
z = floor(1000 * uniform(0));
output;
end;
run;

%ds2csv(data=test, runmode = b, csvfile=c:\temp\test.csv);

The runmode option is b if you're in the program editor. Other options let you customize what vars to include, restrict observations, whether column headers are included, and MIME/HTTP headers. 

Documentation for this little gem is tucked away under: Contents; SAS Products; Base SAS; SAS 9.2 Language Reference: Dictionary; Appendices; SAS Utility Macros.  (Of course!  Where else?)

The documentation claims this only runs within a data step, but the code above shows otherwise.

 

 

 

Contents


RSS feed