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;
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: