I am new to using the "class" statement in Proc Logistic. The output from Proc Logistic using the class statement does not order the Odds ratios in the order of the format or label. The data is looking at pack years of smoking and whether there is a dose response with pack years and cancer.
My format is
Value pkyrcat3f 1='never cig smk'
2='<20 pkyrs'
3='20-<40'
4='>=40';
The labels are
if packy =0 then pkyrcat3= 1; else
if packy >0 and packy <20.00 then pkyrcat3=2; else
if packy >=20.00 and packy <40.00 then pkyrcat3=3;else
if packy >=40.00 then pkyrcat3=4;
Here is the Proc logistic call:
Note: when I used FIRST as the REF for PKYRCAT3, the referent was >=40 years, so I changed the referent to last
and the NEVER smoked category became the referent, which is the correct referent group.
proc logistic data=pan2.pkyr; /*1=case, 2= control*/
class age10yg(ref=first)sex race educat (ref=last) bmiad3cat (ref=first) etoh(ref=first)
diabetes(ref=last) pancreat(ref=last) pkyrcat3(ref=last) / param=ref;
model status= age10yg sex race educat bmiad3cat etoh diabetes pancreat hisp gb_stones pkyrcat3 /
selection = forward
include=11
ctable pprob= (0 to 1 by .1)
outroc=roc;
run;
quit;
From the output the automatically coded dummy variables are:
pkyrcat3 | 20-<40 | 1 | 0 | 0 |
---|---|---|---|---|
<20 pkyrs | 0 | 1 | 0 | |
>=40 | 0 | 0 | 1 | |
never cig smk | 0 | 0 | 0 |
The correct order is as shown in the label. How can the correct order be obtained using the CLASS statement? Does the order NOT MATTER in the Odds Ratio result for looking at dose-response? How can the variable be coded in the correct order using the CLASS statement versus creating manual dummy variables? Thank you.
Just a suggestion, maybe you could change your proc format like this so you don't need to do the if-else statement.
proc format;
Value pkyrcat3f 0='never cig smk'
1-19 ='<20 pkyrs'
20-39='20-<40'
40-high='>=40';
proc logistic data=pan2.pkyr; /*1=case, 2= control*/
format packy pkyrcat3f.;
class age10yg(ref=first)sex race educat (ref=last) bmiad3cat (ref=first) etoh(ref=first)
diabetes(ref=last) pancreat(ref=last) packy (ref='never cig smk') / param=ref;
model status= age10yg sex race educat bmiad3cat etoh diabetes pancreat hisp gb_stones packy /
selection = forward
include=11
ctable pprob= (0 to 1 by .1)
outroc=roc;
run;
quit;
Thanks, SO much,, Removing 'else' did not remove the coding problem. I think using 'packy' as the format might cause a problem because 'packy' is created earlier to differentiate smokers from non-smokers. see below...
/* never smoker =0 and ever smoker =1, must be sure that all variables are calculated based off TOEV because reflects recoding*/
if tobev = 1 then pkyr1=0;
if tobev = 2 then pkyr1=1;
if tobev = 3 then pkyr1=1;
This is used to add the current and former smokers cigarettes per day
if pkyr1=1 then do;
cigsum=sum(cpd, cpd_smkq); end;
Here is where 'packy' is created earlier in the program summing cigarettes and years smoked.
/*PACK YEARS VARIABLE– (cigs per day * yrs smoked) divided by 20 */
if pkyr1= 1 then packy=((cigsum * yrsum) / 20); else
packy=0;
So, is it OK to use 'packy' as the format? other suggestions?
Thanks, Cary
The order doesn't matter for the odds ratio, because all are in comparison to the reference level.
If you want them displayed in a specific order, look at the order option on the class statement, the default is the FORMATTED and it sounds like you want the INTERNAL option instead.
proc logistic data=pan2.pkyr; /*1=case, 2= control*/
class age10yg(ref=first)sex race educat (ref=last) bmiad3cat (ref=first) etoh(ref=first)
diabetes(ref=last) pancreat(ref=last) pkyrcat3(ref=last) / param=ref ORDER=INTERNAL;
model status= age10yg sex race educat bmiad3cat etoh diabetes pancreat hisp gb_stones pkyrcat3 /
selection = forward
include=11
ctable pprob= (0 to 1 by .1)
outroc=roc;
run;
Relevant reference in the documentation:
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.