Hi,
Was wondering if there was a less tedious way to write my below code: Essentially I am trying to say that if the anti retroviral therapy they have is type 3, 4, 5, etc the they are using a combination ART (ie. 2). What I have below works, but is there an easier way to write this out?
DATA dtanl.hivcancerdta;
set dtanl.hivcancerdta;
IF arv1_d1 = . THEN arvtype = .;
ELSE IF arv1_d1 = 3 THEN arvtype = 2;
ELSE IF arv1_d1 = 4 THEN arvtype = 2;
ELSE IF arv1_d1 = 5 THEN arvtype = 2;
ELSE IF arv1_d1 = 11 THEN arvtype = 2;
ELSE IF arv1_d1 = 14 THEN arvtype = 2;
ELSE IF arv1_d1 = 42 THEN arvtype = 2;
ELSE IF arv1_d1 = 44 THEN arvtype = 2;
ELSE IF arv1_d1 = 45 THEN arvtype = 2;
RUN;
Thank you!
DATA dtanl.hivcancerdta;
set dtanl.hivcancerdta;
IF arv1_d1 = . THEN arvtype = .;
ELSE IF arv1_d1 in (3,4,5,11,14,42,44,45) then arvtype = 2;
RUN;
DATA dtanl.hivcancerdta;
set dtanl.hivcancerdta;
IF arv1_d1 = . THEN arvtype = .;
ELSE IF arv1_d1 in (3,4,5,11,14,42,44,45) then arvtype = 2;
RUN;
To repeat the same logic across multiple variables use an array.
array list arv1_d1 arv1_d2 arv1_d3 arv2_d1 ;
arvtype=.;
do index=1 to dim(list) until (arvtype=2);
IF list[index] in (3,4,5,11,14,42,44,45) then arvtype = 2;
end;
Use the IN operator instead of the = operator.
For consecutive integers you can even use the min:max syntax.
IF arv1_d1 = . THEN arvtype = .;
ELSE IF arv1_d1 in (3:5 11 14 42 44 45) THEN arvtype = 2;
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.