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
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.