The script begins by creating a 'comp2010' dataset from in-line data (datalines/cards), calculating additional variables. Then, it defines a macro `%hw6problem1` that encapsulates the `PROC GLM` procedure to fit a linear regression model. A second macro, `%hw6problem2`, uses the first to fit two models (a full and a reduced one), combines their output statistics, and manually calculates an F-test to compare the two models. Finally, the script executes this model comparison twice with different configurations and generates a PDF report.
Data Analysis
Type : CREATION_INTERNE
The 'comp2010' dataset is created directly in the code using a DATA step with a 'cards' statement for data input.
1 Code Block
ODS
Explanation : Opens an ODS destination to generate an output file in PDF format.
Copied!
ods pdf file="HW6NickLipanovich.pdf";
1
ods pdf file="HW6NickLipanovich.pdf";
2 Code Block
DATA STEP Data
Explanation : Creates the 'comp2010' table. Reads the three variables 'winper', 'score', and 'save' from in-line data (cards) and calculates three additional variables: 'save2', 'scoresave', and 'differential'.
Explanation : Displays the content of the 'comp2010' table in the results output.
Copied!
proc print data=comp2010;
run;
quit;
1
PROC PRINTDATA=comp2010;
2
RUN;
3
QUIT;
4 Code Block
MACRO
Explanation : Defines a macro `%hw6problem1` that executes the GLM (General Linear Model) procedure. The macro fits a model ('model') for a dependent variable ('outcome') based on predictors ('modelx'). It can optionally include a classification variable ('classx'). Model statistics are saved to an output table ('myoutstat').
Explanation : Defines a macro `%hw6problem2` to compare two models (a full and a reduced one). It calls the `%hw6problem1` macro twice to fit each model. Then, via DATA steps, it combines the results, calculates the F-test statistic and the associated p-value to assess whether the full model is significantly better than the reduced model. The F-test result is then displayed.
Copied!
%macro hw6problem2 (outcome,classx1,classx2,modelx1,modelx2,myoutstat1,myoutstat2,indata);
%hw6problem1 (&outcome,&classx1,&modelx1,&myoutstat1,&indata);
%hw6problem1 (&outcome,&classx2,&modelx2,&myoutstat2,&indata);
data fullvsreduced;
set &myoutstat1 &myoutstat2;
if _type_="ERROR";
run;
proc sort data=fullvsreduced;
by df;
run;
data fullvsreduced2;
set fullvsreduced;
fullss=lag(ss);
fulldf=lag(df);
num = (ss-fullss)/(df-fulldf);
den = fullss/fulldf;
f = num/den;
pvalue=1-cdf('f', f, df-fulldf, fulldf);
keep f pvalue;
if _n_=1 then delete;
run;
proc print data=fullvsreduced2;
run;
%mend;
Explanation : Calls the model comparison macro `%hw6problem2` twice. The first call compares a model with 'score' and 'save' as predictors to a simpler model with 'differential'. The second call reverses the order of comparison. Results are written to tables 'ssout' and 'dout'.
Explanation : Closes the ODS PDF destination, thus finalizing the file creation.
Copied!
ods pdf close;
1
ods pdf close;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.