I am having an issue when exporting a SAS file to a CSV file. Specifically variables are being exported with their "assigned values" instead of their "raw values". For example there is a dichotomous numerical variable with "raw values" of either 0 or 1 with "assigned values" of 0="no", 1="yes". When exporting the SAS file to a CSV this variable includes its "assigned value" ('Yes' or 'No') instead of the "raw value" (0 or 1) . Is their code that helps avoid this? The following is the code used to export the data:
PROC EXPORT DATA=sas file
Outfile= CSV file
DBMS=csv REPLACE;
PUTNAMES=no;
Run;
Thanks for your help
Take the data step code (created by PROC EXPORT) from the log and de-assign the formats.
You have formats applied to your data then.
You can remove the format ahead of time or apply it as needed to generate the data you want. ODS CSV is a good way to do this as you can easily control the formats within a proc and test it easily.
ods csv file='/folders/myfolders/demo.csv';
proc print data=sashelp.class noobs;
format age 8.2; *formats variable as numeric with 2 decimal places;
run;
ods csv close;
Same answer as here:
https://stackoverflow.com/questions/65814476/exporting-sas-file-to-csv
You can use the _ALL_ variable list.
proc print data=have;
format _all_;
run;
But watch out for date, time or datetime values. You will get the raw number of days or seconds instead if you remove the formats. You can add a second format statement to re-attach them.
proc print data=have;
format _all_;
format date yymmdd10. time time5. datetime datetime19.;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.