Hello,
Can someone please help me with the code to achieve this:
I am creating a variable called a1_level( with 3 levels 0,1 and 2) that considers r1,c1,f1
and d1. Each id should should have a level should meet a combination of 4 conditions:
Level 0: if r1=0 and c1=0 and f1= 0 and d1=0;
Level 2: if r1= 2 or r1=3 and if c1=2 or c1=3 and if f1=2 or f2= and if d1=2 or d1=3;
Level 1: if the subject doesn't meet the level 0 and level 2 conditions.
I created the levels 0 and 2 already but I don't know how to put in level 1; they are the missing
values in Table 2. ie. obs 11, id os13 should have 1. Same with id 15, 24 and 25.
My SAS code, log and results attached.
Please help me.
Thanks.
ak.
From Table 2,
/* Exposure data*/
data d1;
input id$ a1 a2 a3 a4 lung$ 14-21 a1s a2s a3s a4s r1 c1 f1 d1;
datalines;
os1 1 0 0 1 ca case 2 0 0 2 1 1 1 2
os2 1 1 0 0 ca case 1 1 0 0 3 2 3 2
os3 0 0 0 0 pop cont 0 0 0 0 0 0 0 0
os4 1 0 0 1 ca case 2 0 0 1 2 2 2 3
os5 0 1 0 0 ca case 0 1 0 0 0 0 0 0
os6 0 0 0 0 ca case 0 0 0 0 0 0 0 0
os7 1 0 1 1 pop cont 2 0 1 2 1 3 2 1
os8 0 1 0 0 ca case 0 2 0 0 0 0 0 0
os9 1 0 1 0 pop cont 2 0 2 0 3 3 2 2
os10 0 0 1 0 ca case 0 0 1 0 0 0 0 0
os11 0 1 0 0 pop cont 0 2 0 0 0 0 0 0
os12 0 1 0 0 pop cont 0 1 0 0 0 0 0 0
os13 1 1 1 1 pop cont 1 2 1 2 2 3 3 1
os14 0 0 0 0 pop cont 0 0 0 0 0 0 0 0
os15 1 0 0 1 ca case 2 0 0 1 2 1 1 3
os16 0 1 1 0 pop cont 0 2 2 0 0 0 0 0
os17 1 1 1 1 pop cont 2 1 2 1 3 2 2 2
os18 0 0 0 0 ca case 0 0 0 0 0 0 0 0
os19 0 1 0 0 pop cont 0 1 0 0 0 0 0 0
os20 0 0 0 0 ca case 0 0 0 0 0 0 0 0
os21 0 0 0 1 ca case 0 0 0 2 0 0 0 0
os22 1 1 1 0 ca case 1 1 2 0 2 3 3 2
os23 1 0 0 0 ca case 2 0 0 0 3 3 2 3
os24 1 1 0 1 pop cont 2 0 0 2 3 2 1 3
os25 1 1 1 0 ca case 1 1 2 0 2 3 1 2
os26 1 1 1 0 ca case 2 1 2 0 1 2 2 3
;
data d2(keep= id a1 a1s r1 c1 f1 d1 lung); set d1;
proc print data=d2; run;
proc freq data=d2;
tables a1*lung a1s*lung r1*lung c1*lung f1*lung d1*lung;
run;
/* Step 1: Delete r1=1 from dataset leaving only r=2 and r=3 + other relevant variables*/
data exp23;set d2;
if r1=1 then delete;
run;
proc print data=exp23;
title 'Table 1: Keep ever exposed(r=2 and r=3) + other relevant variables';
run;
proc freq data=exp23;
tables r1*lung c1*lung f1*lung d1*lung;
run;
/*Step 2: Create 3 levels: level 0, level 1 and level 2*/
data a1sns;
set exp23;
if r1=0 and c1=0 and f1=0 and d1=0 then a1_level=0;
else if r1>1 and c1 > 1 and f1>1 and d1>1 then a1_level=2;
else if c1 ne 1 and f1 ne 1 and d1 ne 1 then a1_level=1;
run;
proc print data=a1sns;
Title 'Table 2: al levels 0,1 and 2';
run;
proc freq data=a1sns;
tables r1*lung c1*lung f1*lung d1*lung;
run;
Please try this:
data a1sns;
set exp23;
if r1=0 and c1=0 and f1=0 and d1=0 then a1_level=0;
else if r1>1 and c1 > 1 and f1>1 and d1>1 then a1_level=2;
else a1_level=1;
run;
Hi @ak2011 ,
Thanks for responding. In addition, marking the post from @PaigeMiller (not my post) as the solution will help everyone further.
Kind regards,
Amir.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.