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
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 -
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;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.