BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11

Hello Experts,

The values in my data is :

SASdevAnneMarie_1-1664439541859.png

 

 

When I export (proc export)  this values to a csv file I don't have the 0 anymore :

 

SASdevAnneMarie_2-1664439572101.png

 

Do you know, please, how to hold the 0 while exportation ?

 

Thank you for your help  !

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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++.

 

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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++.

 

ballardw
Super User

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.

Tom
Super User Tom
Super User

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;
mkeintz
PROC Star

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.

 

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 577 views
  • 4 likes
  • 5 in conversation