BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sarahsasuser
Quartz | Level 8

Hi All,

I have a data field that I need to split into two new fields. The field is a building code and then name of that building. Example: ID_Number= 1 Bond Street Building

I've been using this code to extract the ID_number:

do while(scan(ID_Number, i, " "));

new_id=scan(LID_Number, i, "  ");

output;

i+1;

end;

That code gives me a new_id field of 1. How do I get "Bond Street Building" into another field?

Thanks,

Sarah

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

One possibility:

   field1 = scan(id_number, 1, ' ');

   field2 = substr(id_number, 2 + length(field1));

Scan is good for getting the first field, but not as good at getting the second field because that one contains multiple words.

Good luck.

View solution in original post

5 REPLIES 5
LinusH
Tourmaline | Level 20

There have been plenty of questions of this sort on the forum. Pls use the search facility to get your answer.

Data never sleeps
Reeza
Super User

Look at the scan function modifiers, specifically 'ka'

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

sarahsasuser
Quartz | Level 8

Thanks Reeza, I'm unable to get that to work either. Is there a second step I'm missing? I've tried the following and the field NewName is not populated.

NewName=compress(ID_Number,,'ka');

NewName=scan(LDMS_ID_Number,2," ","ka");

NewName=scan(ID_Number," ","ka");

NewName = PRXCHANGE('s/[^a-zA-Z]//o',-1,ID_Number);

Astounding
PROC Star

One possibility:

   field1 = scan(id_number, 1, ' ');

   field2 = substr(id_number, 2 + length(field1));

Scan is good for getting the first field, but not as good at getting the second field because that one contains multiple words.

Good luck.

sarahsasuser
Quartz | Level 8

Thank you, that was exactly what I was looking for.

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
  • 5 replies
  • 1125 views
  • 0 likes
  • 4 in conversation