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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1284 views
  • 5 likes
  • 4 in conversation