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

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

Capture.JPG

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
state=zipstate(substr(zipcode_5,1,5));

The SUBSTR function in this case selects the first 5 characters.

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
state=zipstate(substr(zipcode_5,1,5));

The SUBSTR function in this case selects the first 5 characters.

--
Paige Miller
Student77
Obsidian | Level 7

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.

Student77
Obsidian | Level 7

perfect thanks!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 1682 views
  • 0 likes
  • 2 in conversation