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

Hello,

 

I need to create a variable based on responses from another variable as follows:

 

if KN2 = 1 and 2, or 3, or 8, AND KN3 = 1, 2, or 3 then I2 = 1; esle I2 = 0.

 

Right now I'm using the following code:

if ((kn2 = 1 and kn2 = 2) or kn2 in (3,8)) and kn3 in (1:3) then i2 = 1;
else i2 = 0;

 

Is there a better way to write this code? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
aowais
Obsidian | Level 7

The question was multiple response, and data were entered as needed; i.e. KN2 = 1 if respondant answered with 1 AND 2, or 3 or 8; 0 otherwise.

View solution in original post

4 REPLIES 4
Astounding
PROC Star
How is it possible for kn2 to be both 1 and 2 at the same time?

You may need to understand the requirements better.
aowais
Obsidian | Level 7
Thanks, yes I misread the requirement.
SASKiwi
PROC Star

What is the correct requirement then?

aowais
Obsidian | Level 7

The question was multiple response, and data were entered as needed; i.e. KN2 = 1 if respondant answered with 1 AND 2, or 3 or 8; 0 otherwise.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1343 views
  • 3 likes
  • 3 in conversation