Hello,
I am taking a Biostatistics class and we use SAS. One homework question I couldn't figure out how to write the code
"Taking obesity as response variable, conduct model selection using backward method with maximum model including following covariates: WASIT_HIP_RATIO, Louisa, SBP, AGE, chol, stab_glub, glyhb, HDL, and MALE. "
I followed the likelihood ratio test code that is provided on the course material note which is:
"proc logistic data=temp;
Using option SELECTION= .
model obesity(event='1')=Waist_Hip_ratio Louisa SBP AGE chol stab_glub glyhb HDL MALE /selection=backward;
If the code you are showing produces errors or warnings, show us the LOG. We need to see the entire log from PROC LOGISTIC from the first line of code all the way down to the last NOTE after the PROC, all of it, 100% of the log for this PROC, with nothing chopped out or re-ordered. Paste the log as text into the window that appears when you click on the </> icon, this causes the log to be properly formatted (I no longer try to read logs that are not properly formatted).
If the output is not what you expect, show us the output. A screen capture of incorrect output is fine.
Thank you for your reply. I ran all the codes to give you a better understanding of what I want.
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 PROC IMPORT OUT= WORK.temp DATAFILE= "/folders/myfolders/diabetes.csv" 74 DBMS=CSV REPLACE; 74 ! GETNAMES=YES; DATAROW=2; 75 RUN; NOTE: Unable to open parameter catalog: SASUSER.PARMS.PARMS.SLIST in update mode. Temporary parameter values will be saved to WORK.PARMS.PARMS.SLIST. 76 /********************************************************************** 77 * PRODUCT: SAS 78 * VERSION: 9.4 79 * CREATOR: External File Interface 80 * DATE: 21MAR21 81 * DESC: Generated SAS Datastep Code 82 * TEMPLATE SOURCE: (None Specified.) 83 ***********************************************************************/ 84 data WORK.TEMP ; 85 %let _EFIERR_ = 0; /* set the ERROR detection macro variable */ 86 infile '/folders/myfolders/diabetes.csv' delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ; 87 informat ID best32. ; 88 informat CHOL best32. ; 89 informat STAB_GLUB best32. ; 90 informat HDL best32. ; 91 informat CHOL_HDL_RATIO best32. ; 92 informat GLYHB best32. ; 93 informat LOCATION $10. ; 94 informat AGE best32. ; 95 informat GENDER $6. ; 96 informat HEIGHT best32. ; 97 informat WEIGHT best32. ; 98 informat FRAME $6. ; 99 informat SBP1 best32. ; 100 informat DBP1 best32. ; 101 informat SBP2 best32. ; 102 informat DBP2 best32. ; 103 informat WAIST best32. ; 104 informat HIP best32. ; 105 informat TIME best32. ; 106 format ID best12. ; 107 format CHOL best12. ; 108 format STAB_GLUB best12. ; 109 format HDL best12. ; 110 format CHOL_HDL_RATIO best12. ; 111 format GLYHB best12. ; 112 format LOCATION $10. ; 113 format AGE best12. ; 114 format GENDER $6. ; 115 format HEIGHT best12. ; 116 format WEIGHT best12. ; 117 format FRAME $6. ; 118 format SBP1 best12. ; 119 format DBP1 best12. ; 120 format SBP2 best12. ; 121 format DBP2 best12. ; 122 format WAIST best12. ; 123 format HIP best12. ; 124 format TIME best12. ; 125 input 126 ID 127 CHOL 128 STAB_GLUB 129 HDL 130 CHOL_HDL_RATIO 131 GLYHB 132 LOCATION $ 133 AGE 134 GENDER $ 135 HEIGHT 136 WEIGHT 137 FRAME $ 138 SBP1 139 DBP1 140 SBP2 141 DBP2 142 WAIST 143 HIP 144 TIME 145 ; 146 if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */ 147 run; NOTE: The infile '/folders/myfolders/diabetes.csv' is: Filename=/folders/myfolders/diabetes.csv, Owner Name=root,Group Name=vboxsf, Access Permission=-rwxrwx---, Last Modified=16Mar2021:21:49:57, File Size (bytes)=36704 NOTE: 403 records were read from the infile '/folders/myfolders/diabetes.csv'. The minimum record length was 66. The maximum record length was 100. NOTE: The data set WORK.TEMP has 403 observations and 19 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.02 seconds 403 rows created in WORK.TEMP from /folders/myfolders/diabetes.csv. NOTE: WORK.TEMP data set was successfully created. NOTE: The data set WORK.TEMP has 403 observations and 19 variables. NOTE: PROCEDURE IMPORT used (Total process time): real time 0.21 seconds cpu time 0.17 seconds 148 data temp1; set temp; 149 SBP= MEAN(SBP1,SBP2); 150 Waist_Hip_ratio= waist/hip; 151 if gender='male' then male=1; else if gender='female' then male=0; 152 if location="Louisa" then Louisa=1; else if location="Buckingham" then Louisa=0; 153 BMI=weight*0.454/(height*0.0254)**2; 154 if BMI>30 then OBESITY=1; else if BMI<=30 then OBESITY=0; if BMI=. then OBESITY=.; 155 run; NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 5 at 149:6 2 at 150:23 1 at 153:11 5 at 153:25 NOTE: There were 403 observations read from the data set WORK.TEMP. NOTE: The data set WORK.TEMP1 has 403 observations and 25 variables. NOTE: DATA statement used (Total process time): real time 0.02 seconds cpu time 0.02 seconds 156 157 proc logistic data=temp1; 158 model OBESITY(event='1')= Louisa male Louisa*male; 159 run; NOTE: PROC LOGISTIC is modeling the probability that OBESITY=1. NOTE: Convergence criterion (GCONV=1E-8) satisfied. NOTE: There were 403 observations read from the data set WORK.TEMP1. NOTE: PROCEDURE LOGISTIC used (Total process time): real time 0.32 seconds cpu time 0.29 seconds 160 proc logistic data=temp1; 161 class louisa male; 162 model obesity(event='1')=louisa male; 163 run; NOTE: PROC LOGISTIC is modeling the probability that OBESITY=1. NOTE: Convergence criterion (GCONV=1E-8) satisfied. NOTE: There were 403 observations read from the data set WORK.TEMP1. NOTE: PROCEDURE LOGISTIC used (Total process time): real time 0.31 seconds cpu time 0.26 seconds NOTE: PROCEDURE LOGISTIC used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: The SAS System stopped processing this step because of errors. 164 proc logistic data=temp1; 165 model obesity(event='1')=Waist_Hip_ratio Louisa SBP AGE chol stab_glub glyhb HDL MALE; 166 contrast 'lrt' SBP 1; AGE 1; chol 1; stab_glub 1; glyhb 1; HDL 1; MALE 1; ___ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 167 run; 168 169 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 181
Thank you. I specifically asked for "We need to see the entire log from PROC LOGISTIC" and not the rest of the program.
Your error is in the CONTRAST statement, which seems to me to be irrelevant to a likelihood ratio test, and so you should remove the CONTRAST statement and run the code again.
Sorry about that. I thought it will give you a better understanding.
I removed the contrast and it worked. How can I do forward and backward method with maximum model?
Thank you so much for your help.
I think you are asking the wrong person here, as I despise all forms of stepwise regression, and so I never tell people how to do such a thing. Please go to your favorite internet search engine and type in "problems with stepwise regression".
Using option SELECTION= .
model obesity(event='1')=Waist_Hip_ratio Louisa SBP AGE chol stab_glub glyhb HDL MALE /selection=backward;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.