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

I'm using SAS version 9.4

I have very limited experience using SAS so there might be a really easy answer here, but bear with me.

I have a dataset with 1431 observations and 78 variables. In question are 15 variables with responses of 1, 2, 3, or 9. I would like to create a new variable called MDR that meets the following criteria:

If at least 3 of the 15 variables have a response of 2 or 3, then MDR=1.

Or if creating a new variable is what's hampering me, if there is a way to just keep those with the aforementioned criteria, that would be fine.

All I can think to do is write a seemingly endless if-then-else statement…basically doing by hand what I have to assume SAS could do on its own if I knew the correct code or procedure to use!

Can you help?

Thank you!!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

What I call programmers trick #27 might help. The "trick" is based on when SAS does a logical comparison it returns 0 for false and 1 for true. So you can add, or sum them.

if sum(var1 in (2,3),var2 in (2,3),var3 in (2,3),var4 in (2,3),var5 in (2,3) <continue in the obvious fashion>) ge 3 then MDR=1;

OR

MDR = (sum(var1 in (2,3),var2 in (2,3),var3 in (2,3),var4 in (2,3),var5 in (2,3) <continue in the obvious fashion>) ge 3); will create a 1/0 value

View solution in original post

2 REPLIES 2
ballardw
Super User

What I call programmers trick #27 might help. The "trick" is based on when SAS does a logical comparison it returns 0 for false and 1 for true. So you can add, or sum them.

if sum(var1 in (2,3),var2 in (2,3),var3 in (2,3),var4 in (2,3),var5 in (2,3) <continue in the obvious fashion>) ge 3 then MDR=1;

OR

MDR = (sum(var1 in (2,3),var2 in (2,3),var3 in (2,3),var4 in (2,3),var5 in (2,3) <continue in the obvious fashion>) ge 3); will create a 1/0 value

gros0265
Calcite | Level 5

It worked!! Oh ballardw, thank you so much. Smiley Happy

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 766 views
  • 0 likes
  • 2 in conversation