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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1114 views
  • 0 likes
  • 5 in conversation