BookmarkSubscribeRSS Feed
Susan17
Calcite | Level 5

I have a large data set with a column called ‘identifier.’ About 90% of cases include a 7 digit ID in the identifier column. For the remaining 10% of cases, however, there wasn’t a 7 digit ID available, so the person who created the data set made up her own faux ID by concatenating address and zip code. I need to split out the “true” IDs so I can use them to merge with another file. I want to leave the ‘identifier’ column as is, since the faux IDs may be helpful in some circumstances, but create a new numeric column called ID that only includes the 7 digit ID numbers (and leaves the rest blank). I’m very new to SAS, so I’m sure there’s a simple solution but I just don’t know it! I’ve tried using trim and subst commands but I just can’t get this to work.

 

Here's an example of the data I have to work with (the final column is the result I’m looking for):

 

Identifier                        address               zip            ID

1234567                         240 Main Ave.      44230       1234567

7654321                         800 Elm St.          43240        7654321

211980thSt43215           22119 80th St.      43215        .

 

Thanks in advance for any help you can give.

 

Susan

1 REPLY 1
novinosrin
Tourmaline | Level 20

if length(Identifier  )=7 then id=Identifier                        ;

 

or safe bet-->

if length(identifier)=7 and anyalpha(identifier)=0 then id=identifier;
data want;
set have;
if length(identifier)=7 and anyalpha(identifier)=0 then id=identifier;
run;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 1260 views
  • 0 likes
  • 2 in conversation