Question

I have around 720 SAS datasets (which are equipped with 720 SAS index files ".sas7bdnx") within a single folder that I would like to convert to CSV files. I know how to use proc export to convert one at a time, but any efficient way to do the conversion for all in a one SAS program? All the datasets are stored on a local unix server.

Was it helpful?

Solution

This is fairly simple, contingent upon you having some reasonable way to identify them in code.

Here is the simple answer:

%macro makeCSV(dataset=);
proc export data=&dataset. file="&dataset..csv" dbms=csv replace;
run;
*modify export if needed;
%mend makeCSV;

proc sql;
  select cats('%makeCSV(dataset=',memname,')') into :makeCSVlist separated by ' '
    from dictionary.tables
    where libname='YOURLIB' and memname like 'FORCSV';
quit;
*or whatever logic identifies these 720 or whatnot datasets;
&makeCSVlist; *actually runs the macro calls;

Now, that's probably fairly slow, but it should work. Faster would be not to have 720 datasets, but one dataset, and write out the code in a data step using FILEVAR= option. That becomes a little difficult if you have a huge number of variables (as you do have to write a put statement out) but even then you can generate code sort of like what I just did using dictionary.columns. That would still generate 720 CSVs, but it's much faster because it avoids the 720 proc export calls and their overhead.

OTHER TIPS

There is an appilcation called SAS2SPSS which uses SPSS conversion to make them spss files which can then be converted to virtually any other format, excel, csv, xml, etc. You can just Google SAS2SPSS or go to

http://the-chronicon.blogspot.com/p/sas2spss.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top