BookmarkSubscribeRSS Feed
Ravikumarpa4
Obsidian | Level 7
I've N number of zip codes but I need zip code minimum should be 6 numbers if less then it should prefix with '0'. Please help me on this
5 REPLIES 5
Kurt_Bremser
Super User

If it is already stored as character, do this:

zipcode = put(input(zipcode,best.),z6.);

else, you need to convert to character:

zipcode_char = put(zipcode,z6.);

or you simply assign it the format for display:

format zipcode z6.;
Ravikumarpa4
Obsidian | Level 7
Complete data in number format so I can use as format option right?

Regards
Ravikumar

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Reeza
Super User

Depends. Try it and see if it meets your requirements. 

Kurt_Bremser
Super User

Converting to number and then using a format provides for the simplest code. But you might to have to solve other issues (blanks within zipcodes etc) first for this to work.

In this like in most other cases, testing beats speculating

(German: "Probieren geht über studieren", English: "The proof of the pudding is in the eating")

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Whilst I agree with the above, if number convert is easiest, if the data contains non numerics that isn't going to work, so here is a text version:

data want;
  input zip $;
  if lengthn(zip) < 6 then zip=cats(repeat("0",5-lengthn(zip)),zip);
datalines;
12345
123456
12AE4
1
;
run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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