BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mauri0623
Quartz | Level 8

I create a .csv file from a SAS dataset. When I do this I loose the leading zeros on columns IPAC where the IPAC starts with 0000 and then the number.

 

Example, 00003801 will becomes 3801 and I loose the first 4 zeros. Any ideas how to see the leading zeros in the .csv file.

1 ACCEPTED SOLUTION

Accepted Solutions
mauri0623
Quartz | Level 8

I am putting out a .csv file and not an excel file. I found the solution and it work. Basically using options will solve the issue.

 

ods _all_ close;

%let my_csv_file = C:/users/Mauri.Esfandiari/Documents/Missinginfo_to_Validate_&timestamp..csv;

ods csvall file = "&my_csv_file." options (prepend_equals="yes"

quote_by_type="yes");

proc print data = sas_perm.miss_ipac_odn_acc_0919 noobs;

title "Missing IPACs, ODNs, Accounting, and psudo IPACs";

run;

ods csvall close;

View solution in original post

6 REPLIES 6
Patrick
Opal | Level 21

@mauri0623 

Are you opening the .csv with a text editor or with Excel? 

Excel will read the string as a number and omit the leading zeroes. Excel doesn't really show you what's in the .csv but it will interpret the values in the .csv and convert it to Excel. 

If the zeroes are already missing in the .csv text file itself (opened with a text editor like Notepad) then use a Zn. format for writing the numbers.

mauri0623
Quartz | Level 8

Opening the .csv file in notepad ++ still shows the leading zeros missing.

ballardw
Super User

@mauri0623 wrote:

Opening the .csv file in notepad ++ still shows the leading zeros missing.


If you first opened in Excel and then saved it, such as after widening columns to see values then Excel likely "corrupted" the values.

You did not say that you never opened the file in Excel.

Cynthia_sas
SAS Super FREQ

Hi:
IF you are creating output for Excel, you have more choices than creating a CSV file. You have ODS CSV (plain text CSV file with no formatting), ODS TAGSETS.EXCELXP (Spreadsheet XML format 2003) and ODS EXCEL (XLSX format 2007).

If you are running SAS 9.4 then you should try ODS EXCEL. It will create an XLSX file that does respect the Zn. format, as shown in the output example below:

lead_zero_ods_excel.png

Cynthia

mauri0623
Quartz | Level 8

I am putting out a .csv file and not an excel file. I found the solution and it work. Basically using options will solve the issue.

 

ods _all_ close;

%let my_csv_file = C:/users/Mauri.Esfandiari/Documents/Missinginfo_to_Validate_&timestamp..csv;

ods csvall file = "&my_csv_file." options (prepend_equals="yes"

quote_by_type="yes");

proc print data = sas_perm.miss_ipac_odn_acc_0919 noobs;

title "Missing IPACs, ODNs, Accounting, and psudo IPACs";

run;

ods csvall close;

Tom
Super User Tom
Super User

How does that actually solve the problem?  

You seem to have just added two extra lines above the actual data with a tile and a bunch of unneeded quotes around values that don't actually contain any delimiters that would make the quotes necessary.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 6 replies
  • 2545 views
  • 0 likes
  • 5 in conversation