## DATA Step, Macro, Functions and more

Solved
Occasional Contributor
Posts: 5

Hi Team,

I have a Zip Code  1235

0234

Need result as        12350000

02340000

Accepted Solutions
Solution
‎04-27-2018 06:01 AM
Super User
Posts: 9,853

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;```

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

All Replies
Solution
‎04-27-2018 06:01 AM
Super User
Posts: 9,853

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;```

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

Regular Contributor
Posts: 164

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 -

Super User
Posts: 10,850

``````data have;
zip='1235';output;
zip='0234';output;
run;
data want;
length zip \$ 8;
set have;
newzip=translate(left(zip),'0',' ');
run;``````
Super User
Posts: 13,941

@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.

☑ This topic is solved.