BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AJChamberlain
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
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;
--
Paige Miller
novinosrin
Tourmaline | Level 20

hey i solved this in the other thread lol

 

with a bonus sample dataset as well haha

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2223 views
  • 1 like
  • 4 in conversation