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

I would like to be able to join variables 1-4 into one variable based on the value.

 

data have;
input var1 var2 var3 var4;
cards;
1 91 98 1
2 1 91 2
2 2 91 2 
1 98 2 91
2 2 2 2 ; run;

I want the output to be set so if there is a value of '1' in var1, var2, var3, or var4, the output will be 1. If there is not a value of '1' in any of the four variables, I want the output to be 0.  I'm not sure how to go about this. Thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input var1 var2 var3 var4;
cards;
1 91 98 1
2 1 91 2
2 2 91 2 
1 98 2 91
2 2 2 2
;
run;

data want;
   set have;
   array var var:;
   v = (1 in var);
run;

 

Result:

 

var1 var2 var3 var4 v 
1    91   98   1    1 
2    1    91   2    1 
2    2    91   2    0 
1    98   2    91   1 
2    2    2    2    0 

View solution in original post

2 REPLIES 2
mar0000
Obsidian | Level 7
data have;
input var1 var2 var3 var4;
cards;
1 91 98 1
2 1 91 2
2 2 91 2 
1 98 2 91
2 2 2 2
;
run;

The example code was messed up. This is more accurate.

PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input var1 var2 var3 var4;
cards;
1 91 98 1
2 1 91 2
2 2 91 2 
1 98 2 91
2 2 2 2
;
run;

data want;
   set have;
   array var var:;
   v = (1 in var);
run;

 

Result:

 

var1 var2 var3 var4 v 
1    91   98   1    1 
2    1    91   2    1 
2    2    91   2    0 
1    98   2    91   1 
2    2    2    2    0 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 448 views
  • 1 like
  • 2 in conversation