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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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