Hello, I have a question on how to run a query in a better way. I am thinking an array may work here but am stumped at how. I have a data set that has 5 code values. I need to use a combination of codes to create a new category. I have a dataset called have below: data have;
length service_type $10;
input ID $ code1 code2 code3 code4 code5 ;
datalines;
1 11 7 13 986 0
2 17 309 13 0 0
3 11 922 357 999 999
4 18 300 0 0 999
5 20 7 0 0
6 749 984 0 0 0
7 750 751 0 0 999
8 34 15 4 0 0
9 999 1 0 0
10 13 0 0 0 0
11 11 0 0 13 999
12 18 0 1 0 0
13 17 0 0 0 0
14 16 1 0 0 0
15 300 0 0 1 0
16 749 0 0 751 0
run; I can use the below if-then-else statement to create my categories, where I have multiple 'or' statements, but is there a better way to run the below code. In this example, I only showed 5 codes, but in reality, I have a dataset with about 25 codes. Where code1 remains the same, what changes are codes 2 to 25. data want;
set have;
if (code1 in (11,17,18) and code2 =7) or (code1 in (11,17,18) and code3 =7)
or (code1 in (11,17,18) and code4 =7)
or (code1 in (11,17,18) and code5 =7) then cars='1'; else cars='0';
if (code1 in (11,17,18) and code2 =13) or (code1 in (11,17,18) and code3 =13)
or (code1 in (11,17,18) and code4 =13)
or (code1 in (11,17,18) and code5 =13) then trucks='1'; else trucks='0';
if (code1 = (749) and code2 in (984,751)) or (code1 = (749) and code3 in (984,751))
or (code1 = (749) and code4 in (984,751))
or (code1 = (749) and code5 in (984,751)) then pickup='1'; else pickup='0';
run; Thank you in advance!
... View more