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.
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;
Please post the complete log of that step.
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;
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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.