Friday, April 1, 2011

How to preserve leading zeros when export to csv file

Reactions: 
data one;
input id $;

/* create formatting to preserve leading zeros in excel */
cid  =  ' = " '  ||  id  ||  ' " ';

cards;
00123
12398
01234
00034
;
run;

data one (drop=id);
      set one;
run;

ods listing close;

ods csv file='lead0.csv' ;

      proc print data=one noobs;
      run;

ods csv close;

3 comments:

Jian said...

Just curious: How did you get this info? The other workaround, at least for native xls, is to put a "'" in front of the number. For example, "10" is set as "'10".

Anonymous said...

This tip was tremendously helpful. Thank you!

Cub Training said...

It was very nice article and it is very useful to SAS OC learners.We also provide Cub training software online training.