Efficiently convert a SAS dataset into a CSV

The answers here have addressed many ways to create a csv, but not necessarily the efficiency of these methods. I create a sample dataset (temp) with 100,000 rows and five columns to test and compare the methods for export the sas dataset to a csv named temp.csv.


The first method: The Export Procedure. Run time: 0.43 seconds.

PROC EXPORT data=temp 
     outfile="temp.csv" dbms=csv replace;

Quick run time and simple, in-the-box flexibility when choosing other options. With that said, it is not the strongest for customization


The second method: ODS with Print Procedure. Run time: 14.09 seconds.

ODS csv file="temp.csv";
PROC PRINT data=temp noobs;
RUN;
ods csv close;

This method is the worst option out of the three for most use cases, although there a few special use cases. It is nice for temporary output of previously written procedures, especially if you want the output to stay in the lst file (if it is not too big). It also may be useful when you want to convert another procedure (for instance, a complicated tabulate) to file without further manipulation. If you do not need the print out in the lst file, close your listing (ods listing close) or this will take much, much longer.


The third method: File Statement. Run time: 0.06 seconds.

DATA _null_;
    FILE "temp.csv ";
    SET temp;
    put (_all_) (',');
RUN;

While the performance of this method is not bad, it is not intuitive and looks confusing. As mentioned above however, you would have more control over the output, and it has the quickest run time of them all.


5 different ways to create .CSV file of a SAS dataset.

refer http://studysas.blogspot.com/2009/02/how-to-create-comma-separated-file-csv.html


something along these lines?

proc export data=sashelp.class
    outfile='c:\temp\sashelp class.csv'
    dbms=csv
    replace;
run;

Tags:

Csv

Sas