Here's a situation that comes up pretty often. You receive a file that contains zip codes. It's an excel file and you need to create a SAS data set out of it, so you can do some nifty market analysis. No problem, you clickety clickety through the SAS import wizard and voila! a data set is created. However, the zip_code variable is numeric and doesn't have leading zeroes.
Even though zip codes are made up of numbers, we generally want to treat them as character data. Luckily for you it is easy to turn those numeric variables character and restore the leading zeroes.
In general you:
1) Rename your original numeric zip code variable.
2) Create a new character zip code variable.
3) Apply the z. format to the numeric value to make it character and
restore the missing leading zeroes.
Here is what it looks like in practice:
data myData(drop= bad_zip);
length zip_code $5;
set someData( rename= ( zip_code = bad_zip ));
zip_code = put( bad_zip, $z5. );
run;
Hi there,
ReplyDeleteI am considering to start a website like
r-bloggers.com/about
For sas bloggers.
Would you be interested in joining?
(you may contact me at: tal.galili@gmail.com)
Nice one..
ReplyDeleteHello there
ReplyDeleteI'd like to invite you to add your blog to the new:
http://sas-x.com/
Website.
It's a news website, all dedicated to SAS, based on bloggers content.
I am it's founder, and I created it after creating a similar (and somewhat successful) such website around the topic of R programming. That website can be seen at:
http://www.r-bloggers.com/
If you are interested in joining, you can simply add your site at:
http://sas-x.com/add-your-blog/
Best wishes,
Tal