I have a large SAS dataset raw_data
which contains data collected from various countries. This dataset has a column "country" which lists the country from which the observation is originated. I would like to export a separate .csv file for each country in raw_data
. I use the following data step to produce the output:
data _null_;
set raw_data;
length fv $ 200;
fv = "/directory/" || strip(put(country,$32.)) || ".csv";
file write filevar=fv dsd dlm=',';
put (_all_) (:);
run;
However, the resulting .csv files no longer have the column names from raw_data
. I have over a hundred columns in my dataset, so listing all of the column names is prohibitive. Can anyone provide me some guidance on how I can modify the above code so as to attach the column names to the .csv files being exported? Any help is appreciated!