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

Hi there,

I'm trying to create a 4-5 digit ID number (final_id) using something that looks like the following data:

pat_idstate_idcounty_idhavecounty_idwantfinal_id

1

45300345003
24540544054
337987983798
473693697369
59865165198651
632600632006

I'm having two problems:

1. county_idwant needs to be three digits (state_id is to remain untouched). I need to either 1 zero or two zeroes to the front end to some of these values.

2. How do I merge state_id and county_idwant to get one final numeric value

Any help is greatly appreciated. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

In a datastep:

final_id = state_id*1000 + county_idhave;

You can display county_Idhave using a Z3.0 format and not create a new variable for most purposes. If the only purpose was the create the final_id then not needed as above.

If this is USA data I would strongly recommend looking into FIPS for place identification codes.

View solution in original post

3 REPLIES 3
ballardw
Super User

In a datastep:

final_id = state_id*1000 + county_idhave;

You can display county_Idhave using a Z3.0 format and not create a new variable for most purposes. If the only purpose was the create the final_id then not needed as above.

If this is USA data I would strongly recommend looking into FIPS for place identification codes.

jcooper3
Calcite | Level 5

Thank you! This was much simpler than I thought it would. Thanks again. Smiley Happy

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1239 views
  • 3 likes
  • 3 in conversation