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!
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
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.
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
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!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: