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

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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