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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.