Hi there,
I'm trying to create a 4-5 digit ID number (final_id) using something that looks like the following data:
| pat_id | state_id | county_idhave | county_idwant | final_id |
|---|---|---|---|---|
1 | 45 | 3 | 003 | 45003 |
| 2 | 4 | 54 | 054 | 4054 |
| 3 | 3 | 798 | 798 | 3798 |
| 4 | 7 | 369 | 369 | 7369 |
| 5 | 98 | 651 | 651 | 98651 |
| 6 | 32 | 6 | 006 | 32006 |
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!
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.
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.
Thank you! This was much simpler than I thought it would. Thanks again. ![]()
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.