DOC PREVIEW
SDSU STAT 700 - SAS Lab

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Lab 4: SAS LabIn today’s lab, we will be using SAS to redo select homework problems. We will not focus on SAS code syntax, butrather the output that SAS gives us and it compare it to what we already have calculated in R. If you would like to later explore the code, I have tried to provide as many comments as possible to indicate what SAS is doing. There are many options in how you do analysis in SAS, the code we will be using today simply requires that you just run the code. For the purpose of keeping the tutorial short, we will only look at residual plots and QQ plots as diagnostics.The three problems we will revisit are:HW#2, Problem 1, GPA dataHW#3, Problem 1, chickwts dataHW#4, Problem 2, poison dataGetting started:First, please download the following data sets from Dr. Bailey’s website and save them to your computer. Remember where you saved them because we will need the path name of the file to bring the data into SAS.http://www-rohan.sdsu.edu/~babailey/stat700/gpa.dathttp://www-rohan.sdsu.edu/~babailey/stat700/chickwts.dathttp://www-rohan.sdsu.edu/~babailey/stat700/poison.datPlease locate SAS 9.1 on your computer. Unlike R, SAS outputs to multiple windows. The EDITOR window is where you input your code. The OUTPUT window shows what you have compiled. The LOG window shows the CPU process when you compile, as well as any errors on your code. The GRAPH window shows high resolution plots. For each homework problem that we go over, I highly suggest that you use a new EDITOR window. Let’s begin!HW#2, Problem 1, GPA data Purpose: Linear Models with AICCopy the following code into your editor window and change your data file pathname in the ‘infile’ statement. To compile the code, either hit the little running man button at the top toolbar or hit F8 on your keyboard:/* STAT 700 HW2 P1 GPA data Linear Models with AIC */option formdlim='_' nodate pageno=1; *formats output window for nicer viewing;title 'STAT 700 HW2 P1 GPA data';data gpa;infile 'G:\STAT 700\hw2\gpa.dat' firstobs=2; *replace infile with appropriate pathname, and tell SAS to skip header row;input Student GPA SATmath SATverbal HSmath HSenglish; *input header row variables here;*proc print data=gpa; run; *uncomment (remove *) to print data out, it's a good idea to check that SAS imported it properly;proc reg data=gpa outest=est; *in order to see AIC, must ask SAS to output it to another data set;m1: model GPA=SATmath SATverbal HSmath HSenglish /aic; *input full model, ask for AIC option;m2: model GPA=SATmath SATverbal HSmath /aic; *drop HSenglish;m3: model GPA=SATmath SATverbal HSenglish /aic; *drop HSmath;m4: model GPA=SATmath HSmath HSenglish /aic; *drop SATverbal;m5: model GPA=SATverbal HSmath HSenglish /aic; *SATmath;HSenglish: test HSenglish; *tests if HSenglish can be dropped from the model;plot r.*p. /modellab='Residual Plot'; *creates residual plot;plot r.*nqq. /modellab='QQ Plot' noline; *creates qq plot without x=0 line;proc print data=est; run; quit;proc insight data=gpa; *creates multi-way scatter plot;scatter SATmath SATverbal HSmath HSenglish*SATmath SATverbal HSmath HSenglish;run; *proc insight opens another analysis feature in SAS, must close that analysis window to continue SAS;HW#3, Problem 1, chickwts dataPurpose: One-Way ANOVA, Pairwise Testing and Subsetting DataOpen a new editor window and clear your LOG and OUTPUT window. Copy the following code into your editor window and change your data file pathname in the ‘infile’ statement. Compile the code:/* STAT 700 HW3 P1 chickwts data One-Way ANOVA, Pairwise Testing and Subsetting Data */option formdlim='_' nodate pageno=1;title 'STAT 700 HW3 P1 chickwts data';data chickwts;infile 'G:\STAT 700\hw3\chickwts.dat' firstobs=2;input chick weight feed $; *when giving SAS a character variable, must append it with $;*proc print data=chickwts; run;proc glm data=chickwts;class feed; *input factor here;model weight=feed;means feed /cldiff bon; *ask SAS for the confidence limits for the difference of means and the type of comparison;output out=resout p=preds rstudent=exstdres;run; quit;/* other SAS options for multiple comparision are:BON, DUNCAN, DUNNETT, DUNNETTL, DUNNETTU, GABRIEL, GT2, LSD, REGWQ, SCHEFFE, SIDAK, SMM, SNK, T, TUKEY, WALLER */title 'STAT 700 HW3 P1 chickwts data: Boxplots';proc boxplot data=chickwts; *creates boxplots;plot weight*feed;run;title 'STAT 700 HW3 P1 chickwts data: Residual Plot';proc gplot data=resout;plot exstdres*preds;run; quit;/* PROC GLM does not offer plot options, and the QQ plot from PROC UNIVARIATE is so low resolution that it is useless.So, here is the three step process for creating QQ plot with SAS code */*Step 1: Sort the residuals;proc sort data=resout out=sortout; by exstdres;run;*Step 2: Calculate the quantile values for the residuals;data resnorm;set sortout;rankit = probit((_N_-3/8)/(71+1/4)); *in the quantile calculation, must input sample size,here n=71;run;*Step 3: Plot it!;title 'STAT 700 HW3 P1 chickwts data: QQ Plot';proc gplot data=resnorm;plot exstdres*rankit;run; quit;title 'STAT 700 HW3 P1 chickwts data: Data Subset';data sunsoy; *create new dataset;set chickwts; *tell SAS from which you want to use;if feed='soybean' or feed='sunflowe'; *note, the variable sunflower is 'sunflowe'. SAS truncates variables names to 8 characters;*proc print data=sunsoy; run;proc ttest data=sunsoy; *PROC TTEST automatically computes the test for equal variances when doing paired testing;class feed; *we are comparing two classes of feed: sunflower and soybean;var weight; *we are looking at difference in weight;run;HW#4, Problem 2, poison dataPurpose: Two-Way ANOVA, Profile/Interaction Plots, Data TransformationOpen a new editor window and clear your LOG and OUTPUT window. Copy the following code into your editor window and change your data file pathname in the ‘infile’ statement. Compile the code:/* STAT 700 HW4 P2 poison data Two-Way ANOVA, Profile/Interaction Plots, Data Transformation */option formdlim='_' nodate pageno=1; *options to format the output window;title 'STAT 700 HW4 P2 poison data: Original Data';data poison;infile 'G:\STAT 700\hw4\poison.dat' firstobs=2;input poison treatment survival;recipsurv=1/survival; *create new variable, the reciprocal of the survival time;*proc print data=poison; run;proc glm data=poison;class poison treatment; *alpha, beta: our main effects;model survival=poison treatment poison*treatment; *interaction term


View Full Document

SDSU STAT 700 - SAS Lab

Documents in this Course
Load more
Download SAS Lab
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view SAS Lab and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view SAS Lab 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?