Hello, I am using SAS 9.4
and I am trying to compare two columns of data and make a new column that helps me identify if any data in column A is not in column B, (identified by 1=in column, 0=not in column)
Set: Have
A B
Bo Ape
Po Bo
Ro Cool
Fo Lo
No So
Mo Tape
So Yes
set: want
A B match (is data in A in B?)
Bo Ape 1
Po Bo 0
Ro Cool 0
Fo Lo 0
No So 0
Mo Tape 0
So Yes 1
So I am basing the data off of A and finding if any of A's data is found anywhere in B (refer to bolded).
How am I to go about this?
Something like:
data work.have; input A $ B $; datalines; Bo Ape Po Bo Ro Cool Fo Lo No So Mo Tape So Yes ; proc sql; create table work.match as select a, b,a in (select distinct b from work.have) as match from work.have ; quit;
Something like:
data work.have; input A $ B $; datalines; Bo Ape Po Bo Ro Cool Fo Lo No So Mo Tape So Yes ; proc sql; create table work.match as select a, b,a in (select distinct b from work.have) as match from work.have ; quit;
Hello,
A data step solution :
proc sql noprint;
SELECT nobs INTO :nobs TRIMMED
FROM dictionary.tables
WHERE libname="WORK" and memname="HAVE";
quit;
data want;
array Bvals(&nobs.) $ _TEMPORARY_;
if _N_=1 then do i=1 to &nobs.;
set have point=i;
Bvals(i)=B;
end;
set have;
match=(A in Bvals);
run;
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.