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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.