Hello,
I have heard of the zipstate() function, but I am not sure how to first get my data in the correct structure to be able to use it. I want to add 2 columns to the following data, a new variable called zipcode, and a new one called state
.
So I want to figure out first how to extract the first zip, ie the first 5 digits from "zipcode_5" ( we will use the first zipcode, even when there are multiple, since only the state will matter). and then create a state variable, that uses the newly created, single zipcode
I appreciate any help.
Data
state=zipstate(substr(zipcode_5,1,5));
The SUBSTR function in this case selects the first 5 characters.
state=zipstate(substr(zipcode_5,1,5));
The SUBSTR function in this case selects the first 5 characters.
I understand this part, but as I stated, I first need to create a column that selects the first 5 digits in the zipcode_5 variable.
zipstate() does not work for those that have multiple zips, for ex, someone may have a "zipcode_5" of 77550_77555_77553, and zipstate() returns a blank for these.
So I need to first create a column called "zip" where it extracts the first 5 digits from zipcode_5 and then run zipstate on the new variable with single zipcodes.
perfect thanks!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.