BookmarkSubscribeRSS Feed
hwangnyc
Quartz | Level 8

Hi everyone,

 

I have string data in two columns that are separated by commas. I'd like to scan the first column's characters and see if it appears in the second column.

 

Here is some sample data:

 

HaveAHaveB
Homeless, Health Care, AidedHealth Care, Verified, Aided
A,B,CA,C
X,Y,ZJ,K,F

 

This is what I want:

 

HaveAHaveBWant
Homeless, Health Care, AidedHealth Care, Verified, AidedHealth Care, Aided
A,B,CA,CA,C
X,Y,ZJ,K,F.

 

Many thanks in advance!

1 REPLY 1
ballardw
Super User

Untested without data but has a chance of to get started.

 

data want;
   set have;
   length wantstr $100; /* or long enough to hold expected longest value*/
   do i= 1 to countw(HaveA,',');
      if index(haveb, scan(havea,i,','))>0 then wantstr=catx(',',wantstr,scan(havea,i,','));
   end;
   drop i;
run;

Countw  and Scan functions are told to only consider comma as delimiter for finding phrases,

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