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.

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