SAS Programming

DATA Step, Macro, Functions and more
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 .

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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