BookmarkSubscribeRSS Feed
FourLeafCLover
Calcite | Level 5

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

5 REPLIES 5
Reeza
Super User

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 

FourLeafCLover
Calcite | Level 5


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
P {margin-top:0;margin-bottom:0;}



Thank you Reeza, appreciate the reply. Is there a way to remove formats from all variables without specifying each one? I am having this issue with many variables, not just the one. Thanks



Tom
Super User Tom
Super User

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;
FourLeafCLover
Calcite | Level 5


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
P {margin-top:0;margin-bottom:0;}



Thanks Kurt for the quick reply, I do see the data step in the log after running the proc export. Is there code to be added to this data step that de-assigns all the formats. Thanks



SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 741 views
  • 2 likes
  • 4 in conversation