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

Hi all,

 

I'm setting the zip code to be a 5-digit character variable, and adding a leading zero if there are only 4 digits.

data survey;
	infile '/home/uid/zip.csv' delimiter=',' missover firstobs=2 dsd;
        format Zip_Code $5.;
        input Zip_Code $;

/* I've tried all 3 but none of them worked. */ Zip_Code = put(input(Zip_Code, best12.), z5.); Zip_Code = put(Zip_Code, z5. -L); Zip_Code = put(Zip_Code, z5.);

And the error comes out every time

Statement is not valid or it is used out of proper order.
Any hint or help? Thank you in advance!
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
EyalGonen
Lapis Lazuli | Level 10

Hi @aabbccwyt 

 

I just ran the code below and it works fine...Note that I set the variable length to 5 by using the "length" statement and not by using the "format" statement. It does not explain the error you get. Perhaps you should try to narrow down where the error is originating from. Add some "put" statements to the code before each line or use the data step debugger.

 

data _null_;
	length Zip_code $ 5;
	Zip_Code = '1234';
	Zip_Code = put(input(Zip_Code, best12.), z5.);
	put Zip_Code=;
run;

View solution in original post

4 REPLIES 4
EyalGonen
Lapis Lazuli | Level 10

Hi @aabbccwyt 

 

I just ran the code below and it works fine...Note that I set the variable length to 5 by using the "length" statement and not by using the "format" statement. It does not explain the error you get. Perhaps you should try to narrow down where the error is originating from. Add some "put" statements to the code before each line or use the data step debugger.

 

data _null_;
	length Zip_code $ 5;
	Zip_Code = '1234';
	Zip_Code = put(input(Zip_Code, best12.), z5.);
	put Zip_Code=;
run;
aabbccwyt
Obsidian | Level 7

Thank yall for your replies. The code

Zip_Code = put(input(Zip_Code, best12.), z5.);

is correct. I got it wrong because of a typo. I will accept @EyalGonen answer so the topic will be closed. 

Ksharp
Super User
Better post your data "/home/uid/zip.csv", so we can test it where is wrong .

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
  • 1139 views
  • 0 likes
  • 4 in conversation