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

Variable old_ID may include several names for each name in new_ID. I want to have only one name in old_ID for each name in new_id by separating names in old_id into several rows as the following.

Could you show me how to do so? Thank you so much!

Old_ID                                                               New_ID

P006                                                                B01002

P006A                                                               B01002A

PCT003                                                               B02005

P038                                                                       B05002

P047, P052                                                       B08006

P016, P007, P023, P027, P030                               B11001

P024, P008                                                       B11002

P024A, P008A,                                                       B11002A

Old_ID     New_ID

P006             B01002

P006A     B01002A

PCT003     B02005

P038      B05002

P047             B08006

P052             B08006

P016            B11001

P007        B11001

P023            B11001

P027      B11001

P030      B11001

P024      B11002

P008             B11002

P024A      P008A

P008A      P008A

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

data want ; set have ;

  do i=1 by 1 until (scan(old_id,i,',') = ' ');

    new_old_id = scan(old_id,i,',');

    output;

  end;

run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

data want ; set have ;

  do i=1 by 1 until (scan(old_id,i,',') = ' ');

    new_old_id = scan(old_id,i,',');

    output;

  end;

run;

vxhong17
Calcite | Level 5

Hi Tom,

It works. Thank you so much,

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
  • 2 replies
  • 433 views
  • 0 likes
  • 2 in conversation