Bulk Convert Multiple SAS Datasets to CSV Files

I have about 720 SAS datasets (which are equipped with 720 SAS index files ".sas7bdnx") in one folder, which 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 everyone in one SAS program? All datasets are stored on the local unix server.

+4
source share
2 answers

This is pretty simple if you have a reasonable way to identify them in your code.

Here is a 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, perhaps quite slowly, but it should work. It would be faster to not have 720 data sets, except for one data set, and write the code in the data step using the FILEVAR = parameter. This gets a little more complicated if you have a huge amount of variables (since you need to write a put statement), but even then you can generate code like the one I just used with the dictionary. It will still generate 720 CSV, but it is much faster since it avoids 720 export calls and their overhead.

+3
source

There is a SAS2SPSS application that uses SPSS conversion to create their spss files, which can then be converted to almost any other format, excel, csv, xml, etc. You can just use Google SAS2SPSS or go to

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

0
source

Source: https://habr.com/ru/post/1487564/


All Articles