BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11
data one;
input decode $10.;
datalines;
aaaa 
bbbb
cccc
eeee
;
data cm;
input decode $1-14;
datalines;
aaaa a1b1 ew22
vfdf bbbb b1w2
eewe cccc c2c2
dddd de33 eewe
;

Dear,

I have to create a dataset by merging two data sets by decode variable. The output should contain records from cm data set if the values from Cm contains the values in one dataset.

 

From the above input, output should not contain "dddd de33 eewe" as this value 'dddd' not in data one.  

Please suggest. Thank you

 

output;

decode
aaaa a1b1 ew22

vfdf bbbb b1w2

eewe cccc c2c2

3 REPLIES 3
Oligolas
Barite | Level 11

 

PROC SQL;
   CREATE TABLE want AS
      SELECT a.*
      FROM CM a
      INNER JOIN one b
      ON index(strip(a.decode),strip(b.decode))
   ;
QUIT;
________________________

- Cheers -

PGStats
Opal | Level 21

You could use a contains clause

 

proc sql;
select *
from cm
where exists (select decode from one where cm.decode contains strip(decode));
quit;

But if you are looking for words, it might be better to use FINDW which does specifically that:

 

proc sql;
select *
from cm
where exists (select * from one where findw(cm.decode, strip(decode)) > 0);
quit;
PG
Ksharp
Super User
data one;
input decode $10.;
datalines;
aaaa 
bbbb
cccc
eeee
;
data cm;
input decode $1-14;
datalines;
aaaa a1b1 ew22
vfdf bbbb b1w2
eewe cccc c2c2
dddd de33 eewe
;

proc sql;
select cm.decode
 from one,cm
  where cm.decode contains strip(one.decode);
quit;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1252 views
  • 5 likes
  • 4 in conversation