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

Hi Team,

 

I have a Zip Code  1235

                               0234

 

Need result as        12350000

                                02340000

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep.  I am now having to guess if that zip code is a character or numeric variable!  if its numeric then you convert it character:

data want;
  set have;
  new_zip=put(zip_code,z8.);
run;

If its already character:

data want;
  set have;
  new_zip=cats(new_zip,"0000");
run;

 

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep.  I am now having to guess if that zip code is a character or numeric variable!  if its numeric then you convert it character:

data want;
  set have;
  new_zip=put(zip_code,z8.);
run;

If its already character:

data want;
  set have;
  new_zip=cats(new_zip,"0000");
run;

 

Oligolas
Barite | Level 11

Hi,

 

this will do the trick:

data have;
zip='1235';output;
zip='0234';output;
run;
data want;
   length newzip $10;
   set have;
   newzip=strip(zip)||repeat('0',7-lengthn(strip(zip)));
run;


________________________

- Cheers -

Ksharp
Super User
data have;
zip='1235';output;
zip='0234';output;
run;
data want;
   length zip $ 8;
   set have;
   newzip=translate(left(zip),'0',' ');
run;
ballardw
Super User

@msharma1788 wrote:

Hi Team,

 

I have a Zip Code  1235

                               0234

 

Need result as        12350000

                                02340000


I have to say that is the oddest Zip code requirement unless this is a non-United States postal code. US Zipcodes are either 5 character or 5digits a dash and 4 digits: 12345-7890 example.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1748 views
  • 0 likes
  • 5 in conversation