Hello Experts,
The values in my data is :
When I export (proc export) this values to a csv file I don't have the 0 anymore :
Do you know, please, how to hold the 0 while exportation ?
Thank you for your help !
Please do NOT post data as pictures. NEVER. Use a data step with datalines, so we can recreate your data with copy/paste and submit, without having to ask questions about data types and attributes.
Next, NEVER inspect a csv file with Excel. You see what Excel thinks, not what is really contained in the file. Use a proper text editor like Notepad++.
Please do NOT post data as pictures. NEVER. Use a data step with datalines, so we can recreate your data with copy/paste and submit, without having to ask questions about data types and attributes.
Next, NEVER inspect a csv file with Excel. You see what Excel thinks, not what is really contained in the file. Use a proper text editor like Notepad++.
What file format did you export it to?
What program are you using to look at the exported data?
Spreadsheets will typically make decisions about values. So if you create a CSV file and open with a spread sheet then the values are considered numeric and the SPREADSHEET removes the leading zeroes. (Warning: if you SAVE the file after opening with the spreadsheet then it will change values permanently.) So open the file in text reading program like NotePad, WordPad or similar.
Best is to always show the code you used when asking any questions about the result. Copy the text from your editor or log, on the forum open a text box with the </> icon and paste the text. Best is often the log as it will include notes about execution results.
Please show what the CSV file looks like. You posted a photograph of something that looks like a table. A CSV file is a text file. So a CSV file is going to look like TEXT, not like a table.
Your CSV file should look something like:
var1,var2 0214,953 0214,553 0212,419 0213,942
If you cannot figure out how to look at the CSV file, then just ask SAS to show it to you. So if you exported to a file named myfile.csv then run this simple program to dump the first 10 lines from that file to the SAS log so you can look at it.
data _null_;
infile 'myfile.csv' obs=10;
input;
put _infile_;
run;
To confirm the absence of leading zeroes, did you read the CSV file with a text editor? If you did it with Excel, they would not appear even if the csv file has them. If your SAS variable is a character variable (variable CHRX below), or is a numeric variable with an assigned format specifying leading zeroes (FX below), then exporting to a CSV file (i.e. "dbms=csv") will preserve leading zeroes.
Example:
data have;
do x=1,22,333,4444;
; fx=1; chrx=put(x,z4.);
format fx z4.;
output;
put (_all_) (=);
end;
run;
proc export data=have
outfile='c:\temp\x.csv' replace
dbms=csv;
run;
This program produces the x.csv file in the c:\temp directory. Examine it with NOTEPAD or some other ascii editor to confirm preservation of leading zeroes.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.