Pad with leading zeros: importing from Excel to SAS

Reply
Regular Contributor
Posts: 192

Pad with leading zeros: importing from Excel to SAS

My Excel spreadsheet has leading zeros but when I import to SAS they disappear.

I did a search to find a code and found this but am getting warning messages and am wondering if there's something else I need to do or if you have a better way to do this?

data reformat (drop mz_scode); /*drop variable with missing zero*/

         length scode $7;

     set edit (rename = scode=mz_scode);

*--apply z. format to numeric value to make it character adn restore missing leading zeros;

scode=put(mz_scode,$z7.);

run;

For my log, I'm getting this warning:

cocode=put (mz-scode,&z7.);

WARNING:  Variable mz_scode has already been defined as numeric

Thanks!

Trusted Advisor
Posts: 1,131

Re: Pad with leading zeros: importing from Excel to SAS

Hi

Please try the below code, i made few changes to your existing code

data reformat (drop=mz_scode); /*drop variable with missing zero*/

     length scode $ 7;

     set edit (rename =(scode=mz_scode);

*--apply z. format to numeric value to make it character adn restore missing leading zeros;

    scode=put(mz_scode,8.);

run;

Thanks,

Jagadish

Thanks,
Jag
Super Contributor
Posts: 1,636

Re: Pad with leading zeros: importing from Excel to SAS

try:

data reformat (drop mz_scode rename = scode=mz_scode ); /*drop variable with missing zero*/

         length scode $7;

     set edit ;

*--apply z. format to numeric value to make it character adn restore missing leading zeros;

scode=put(mz_scode, z7.);

run;

Super Contributor
Posts: 578

Re: Pad with leading zeros: importing from Excel to SAS

Wouldn't it be better to define the column as character during the import?

Regular Contributor
Posts: 192

Re: Pad with leading zeros: importing from Excel to SAS

Thanks everyone!

Ask a Question
Discussion stats
  • 4 replies
  • 969 views
  • 0 likes
  • 4 in conversation