creation of a numeric id value using two other variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

creation of a numeric id value using two other variables

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!


Accepted Solutions
Solution
‎06-11-2015 05:31 PM
Super User
Posts: 11,343

Re: creation of a numeric id value using two other variables

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


All Replies
Solution
‎06-11-2015 05:31 PM
Super User
Posts: 11,343

Re: creation of a numeric id value using two other variables

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.

Super User
Posts: 7,832

Re: creation of a numeric id value using two other variables

Use 's method. This is also handy when creating a numeric combination of year and month:

wanted_var = year * 100 + month;

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 12

Re: creation of a numeric id value using two other variables

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 233 views
  • 3 likes
  • 3 in conversation