Hi All
Here's another one from me, I hope is easy for you all - a coffee break problem to solve.
I have three sets of variables:
A1-A50
B1-B50
and Match1 to Match 50
I'm comparing A1 with B1, A2 with B2, and so on, and I want to run the simple process:
If A1=B1 then Match1='Match' else Match1='Error'
If A2=B2 then Match2='Match' else Match2='Error'
and so on.
Is there a way to put this into a Do loop? This must be possible I don't want to write this line of code 50 times!
Assistance appreciated.
A
data want;
set have;
array a a1-a50;
array b b1-b50;
array match match1-match50;
do i=1 to dim(a);
if a(i)=b(i) then match(i)='Match';
else match(i)='Error';
end;
drop i;
run;
That's what arrays are for:
array a {50} a1-a50;
......
do i =1 to 50;
if a{i} = ........
data want;
set have;
array a a1-a50;
array b b1-b50;
array match match1-match50;
do i=1 to dim(a);
if a(i)=b(i) then match(i)='Match';
else match(i)='Error';
end;
drop i;
run;
hey i solved this in the other thread lol
with a bonus sample dataset as well haha
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 25. 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.