BookmarkSubscribeRSS Feed
Sean_OConnor
Obsidian | Level 7

Folks,

 

I have three numeric variables which range from 0 to n and I would like to compare if they match across records and if not which way to they disagree. 

 

The name my variables are A , B and C. I've drawn the logic out in a 3 way Venn Diagram but I'm trying to write a if clause in SAS to extract out the information. I have 7 combinations in total.

A

B

C

A=B

A=C

B=C

A=B=C

 

I would like to have something written such as; if A=B=C then Cohort='ABC'

if A=B then Cohort='AB' and so on.

 

Any help on this would be great. 

1 REPLY 1
Kurt_Bremser
Super User

In fact, you have only 5 "combinations":

  1. no match
  2. A=B
  3. A=C
  4. B=C
  5. A=B=C

So my code would look like

data want;
set have;
if a = b and b = c then result = "all match";
else if a = b then result = "A=B";
else if a = c then result = "A=C";
else if b = c then result = "B=C";
else result = "no match";
run;

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1 reply
  • 708 views
  • 1 like
  • 2 in conversation