data test;
a1= "aa";
a2= "bb";
a3= "cc";
b1= "bb";
b2= "bb";
b3= "cc";
/*After comparison*/
comp1= "No";
comp2= "Yes";
comp3= "Yes";
run;
What I am looking for -
if a1 in (b1,b2,b3) the comp1 = 'Yes';
else comp1 = 'No';
as we don't find the match for a1 in any of (b1,b2,b3) then comp1= "No" and our next scenario will be
if a2 in (b1,b2,b3) the comp1 = 'Yes';
else comp2 = 'No';
now we found a match for a2 in b1 then comp2= "Yes" and will not include that column where we found the matching value in next scenario and our next scenario will be
if a3 in (b2,b3) then comp3 = 'Yes';
else comp3 = 'No';
now we found a match for a3 in b2 then comp3= "Yes" and our next scenerio will be if there are anything else
if a4 in (b3) then comp3 = 'Yes';
else comp3 = 'No';
Thanks!
If the values of the a-variables are that simple, this should work:
data want;
set test;
length compare1-compare3 $ 3;
array a_vars[3] a1-a3;
array cmp[3] compare1-compare3;
cmp_string = catx('|', of b1-b3);
do i = 1 to dim(a_vars);
if findw(cmp_string, a_vars[i], '|', 't') > 0 then do;
cmp_string = tranwrd(cmp_string, a_vars[i], ' ');
cmp[i] = 'yes';
end;
else do;
cmp[i] = 'no';
end;
end;
drop cmp_string i;
run;
If the values of the a-variables are that simple, this should work:
data want;
set test;
length compare1-compare3 $ 3;
array a_vars[3] a1-a3;
array cmp[3] compare1-compare3;
cmp_string = catx('|', of b1-b3);
do i = 1 to dim(a_vars);
if findw(cmp_string, a_vars[i], '|', 't') > 0 then do;
cmp_string = tranwrd(cmp_string, a_vars[i], ' ');
cmp[i] = 'yes';
end;
else do;
cmp[i] = 'no';
end;
end;
drop cmp_string i;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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: