Psych 3030 Example SAS Programs

Psych 3030 Home Page || Course Outline || NWK files || SAS Help || Program Directory Tree || What's New? (programs)

With the change to the new Psych Web Server, some program links below may no longer work. Please let me know. The programs listed below are all stored on the Hebb/YorkArts server and on Phoenix. The programs are also linked to the Web, so selecting the highlighted name should display the code in your browser.

If you are also running a SAS session, you can cut/paste the code into the SAS Program Editor window [1]. In the Hebb Lab, they may be also be used as follows: From the Display Manager window in SAS, choose File -> Open into Pgm Editor, then navigate to the directory,

n:\psy3030\examples
    (Sasuser on Lancelot\Home01)
The files are organized here in subdirectories, corresponding to the topic areas listed below. Double-click on the name of the file you want, then press F3 to submit the program to SAS.

[1] Note: External users should be aware that the programs assume that data files are stored in directories DATA and NWK defined by SAS filename statements, and that all macro programs are stored in an autocall library. The filename statements used in the PsychLab are contained in this autoexec.sas file.

Students wishing to obtain the entire collection of SAS programs and data sets for Psych3030 can download PSY3030.ZIP (883K). A .INSTALL file describes how to install these files for use with SAS.


Phoenix

On Phoenix, the files are stored in under the directories:
/courses/as/psyc/macros
/courses/as/psyc3030

Jump to:

[Program Directory Tree || Intro to SAS || Regression analysis || ANOVA || SAS macro programs || Data sets || Anova Project ]

Introduction to SAS

example1.sas src
A sample SAS program, to illustrate a DATA step and PROC steps.

Regression analysis

Sample programs listed here illustrate various techniques for EDA and resistant lines (marked [R]), simple linear regression ([S]), and multiple regression ([M]).

The output icon is linked to Web-enhanced SAS output from the program.

collin.sas src output
[M] Collinearity in regression. Two examples: one of uncorrelated predictors, the other of highly correlated ones, and the associated statistics for detecting collinearity problems in regression.
deathcox.sas src output
[M] Box-Cox analysis of Deaths data. Illustrates the use of the Box-Cox method to choose a transformation of the response variable, with graphic plots of RMSE, and t-value for each predictor vs. lambda (power), and an influence plot for the observations.
diamond.sas src output
[S] Pricing of Diamond rings. Fits three models, and compares predicted values graphically.
fitinfl.sas src output
[M] Influence analysis and plot for fitness data.
lackofit.sas src output
[S] Lack of Fit test for linear regression. Illustrates finding the SS(Pure Error) and conducting the lack of fit test with PROC RSREG.
normplt1.sas src output
[S] Normal probability plot of residuals. Shows 4 different ways to get a normal probability plot of residuals in SAS.
normplt2.sas src output
[S] Normal probability plot of residuals. Regression of crime rate on personal income in the SMSA data, showing the use of the NORMPLOT macro to get a normal QQ plot of residuals.
normplt3.sas src output
[S] Normal probability plot of residuals. Regression of IMR on INCOME from the Nations data, showing the use of the new GRAPHICS option in PROC REG, and the NQPLOT macro to get a normal QQ plot of residuals.
nqpdemo.sas src output
[S] Normal Quantile plot for various distributions. Generates data from 4 different distributions and compares their normal probabilty plots.
nwkt0503.sas src output
[S] Weighted Least Squares Example (NWK Table 5.3). Compares weighted and unweighted least squares in a case where error variance is proportional to X.
nwk10t01.sas src output
[S] Weighted Least Squares Example (NWK Table 10.1). Compares weighted and unweighted least squares in a case where error variance is proportional to X^2.
nwkt0904.sas src output
[M] Life Insurance Example (NWK Table 9.4). A response surface model predicting amount of life insurance carried from annual income and a measure of risk aversion.
nwk08t01.sas src output
[M] Selecting the best predictors (NWK Table 8.1). Predicting survivial time following a particular type of liver surgery from various indicators, using RSQUARE and STEPWISE analysis.
nwk11t01.sas src output
[M] Insurance innovation study (NWK Table 11.1). Dummy variables to allow for differences in intercept and slope.
piecewrk.sas src output
[M] Piecework Operation (NWK Problem 9.7). A polynomial model predicting productivity from age of employees.
resimr.sas src output
[R] Resistant line for IMR data. Fits a resistant line predicting infant mortality rate from per capita income, and compares this with a log-log fit.
resimrb.sas src output
[R] Boxplot of data and residuals for IMR data. Continuation of RESIMR, comparing the distribution of log(IMR) with that of the residuals from the log-log fit.
resline2.sas src output
[R] Fit Resistant line to XY data. Rates of divorce from 1870 to 1960.
resline3.sas src output
[R] Fit Resistant line to XY data. Mortality due to breast cancer in relation to mean annual temperature in European countries.
sampdist.sas src output
[S] Generate sampling distribution of B0, B1. Generates 100 samples of X-Y data to illustrate the sampling distribution of slope and intercept in regression.
spines.sas src output
[R] Resistant line for Spines data. Relation between age (X) and a measure of body size.
therapy.sas src output
[S] Simple regression example: Personality Test vs. Therapy
therapy2.sas src output
[S] Simple regression example: Inference
therapy3.sas src output
[M] Multiple regression example
therapy4.sas src output
[M] Multiple Regression with Dummy Variables and Interaction
therapy5.sas src output
[G] Some graphics for the therapy data
tiretest.sas src output
[M] Tire testing (NWK 10.15). Dummy variables and interaction to test equality of intercepts and slopes.
uspop.sas src output
[S] Growth of US Population, 1790-. Fits a quadratic model and compares that with a model of exponential growth.

ANOVA

These program illustrate various methods for analysis of One-way ANOVA designs (marked [1]), Two-way designs ([2]), and Three-way and more complex designs ([3]).
anxiety.sas src output
[3] Three-way anova: Instructions x Gender x Test, from summary statistics.
barttest.sas src output
[1] Demo of Bartlet's test for homogeneity of variances
bonmult.sas src output
[1] Creates a graph which compares the efficiency of the Bonferroni and Scheffe tests
fpower1.sas src output
Power computations for F test in Balanced Designs. Illustration of use of the FPOWER macro.
imrsprd.sas src
[1] Spread Level plot for Nations data. Illustrates the construction of the spread-level plot to find a transformation to equalize variances in one-way data.
infantm.sas src
[1] Infant Mortality Rates. Illustrates finding a power transformation to equalize variabilty.
learning.sas src output
[1] Foreign language learning: One Way ANOVA. Vocabulary score for 3 methods of teaching foreign language, with contrasts for two comparisons of interest.
multcomp.sas src
[1] Multiple contrast methods. Compare means in the SUCROSE data with various multiple comparison methods (Bonferroni, Tukey, Scheffé), and trend analysis with contrasts.
nwk16t01.sas src output
[1] Kenton Food Company example (NWK Table 16.1)
nwk17t02.sas src output
[1] Rust Inhibitor Example: One way ANOVA (NWK Table 17.2)
nwk17t06.sas src output
[1] Piecework Trainees: Trend analysis (NWK Table 17.4) Number of units produced, in relation to amount of training. Illustrates trend analysis with contrasts, fitting a quadratic model with GLM, and performing a lack of fit test with RSREG.
nwk19t07.sas src output
[2] Castle Bakery Example: Two way ANOVA (NWK Table 19.7)
nwk20t03.sas src output
[2] Two Factor design: Trend contrasts (NWK Table 20.3)
nwk22t01.sas src output
[2] NWK Table 22.1 Growth Hormone Data (Unequal N)
nwk25t01.sas src output
[3] ANCOVA Example, NWK Table 25.1 (Cracker promotion)
nwk25t06.sas src output
[3] Two way ANCOVA: NWK Table 25.11 (Saleable flowers)
owners.sas src output
[1] Regression approach to Anova. A four-group design is analyzed first as an ANOVA model, then as an equivalent regression model using {-1, 0, 1} variables.
probsolv.sas src output
[1] Data from Problem Solving Experiment
samplef.sas src
[1] Sampling Distribution of F statistic in One Way ANOVA. Generates 100 samples each in a 3-group design when H0 is true, and when H0 is false, to illustrate the sampling distribution of the F statistic.
sampleg.sas src
[1] Sampling distribution of F (gplot). Generates a high-resolution plot of the smoothed distribtions of the F statistics found in SAMPLEF SAS.
simple.sas src output
[2] Testing Simple Effects in a 2x3 Design. Illustrates two ways to test simple effects in a two-way design. (In SAS 6.10, there is an easier way, using the /SLICE= option on the LSMEANS statement.)
smsargn.sas src
[1] Crime Rate by REGION in SMSA data Notched Boxplots
smsargng.sas src
[1] Crime Rate by REGION in SMSA data Notched Boxplots (gplot)
sucrose2.sas src output
[1] Sucrose data: Residual Analysis to test the aptness of the model. Boxplots, and spread-level plot to find a power transformation.
sucrose3.sas src output
[1] Retrospective Power Analysis
tukeyt.sas src output
[2] Two way design, n=1: Tukey test for non additivity
tukeytst.sas src output
[2] Response times for 3 types of sentences (n=1)
2by3.sas src output
[2] Data from a 2 x 3 Two Factor Design
3wayex.sas src output
[3] Three Way ANOVA. Data on effects of linguistic activity during retention and type of material on forgetting. Illustrates plots of interaction means, and testing trend contrasts such as A-linear x C.

SAS macro programs

These macro programs are stored in an "autocall" library on the lab server, so you don't need to do anything special to have them included in your work. Simply include lines to call the macro program. For example (assuming you have already read in the NATIONS dataset),
  %normplot(data=nations, var=imr);
will search for an load the NORMPLOT macro (if it has not already been loaded) and invoke the macro with the NATIONS data. The doc icon is linked to documentation for the macro.

See the notes on The SAS Macro Facility for information on SAS macros.

bartlet.sas src
Bartlett's test for homogeneity of variances ;
boxplot.sas src doc
Boxplots (drawn with SAS/GRAPH)
cpplot.sas src doc
Plot Mallow's C(p) and related statistics for model selection
dummy.sas src doc
Produces dummy variables for a discrete regression variable.
fpower.sas src doc
Power as a function of Effect Size (DELTA/SIGMA) and N
normplot.sas src
SAS macro for normal quantile-comparison plot (printer plot version)
nqplot.sas src doc
SAS macro for normal quantile-comparison plot
meanplot.sas src doc
Plot the means and standard errors for a factorial ANOVA design.
outlier.sas src doc
Robust multivariate outlier detection plot.
resline.sas src doc
Macro to fit resistant line to XY data. Also computes a ratio-of-slopes table to diagnose the need for transformations of X or Y for linearity of regression.
rpower.sas src doc
Macro for retrospective power analysis.
scatmat.sas src doc
Scatterplot matrix using SAS/GRAPH.
scatter.sas src doc
Scatterplot matrix using SAS/INSIGHT.
splot.sas src doc
Macro for schematic plots (printer-plot version of boxplot)
symbox.sas src doc
Display boxplots of a variable transformed to various powers
symplot.sas src doc
Macro to display plots for making a distribution symmetric.
tukey1df.sas src
Tukey 1 df test for Additivity in two-way tables with n=1.

Data sets

These files are set up as SAS DATA steps, ready to be used in other programs. They are stored in the DATA directory under PSY3030. To use one of them, you can either use the menu choices File -> Open in Program Editor, or submit a %include statement such as
%include data(boston);
to obtain the BOSTON.SAS data file.
cars93.sas src
[M] Data on 93 cars from 1993.
auto.sas src
[M] The auto data
boston.sas src
[M] The Boston house price data
deaths.sas src
[M] Court awards in cases of wrongful death
draftusa.sas src
USA Draft Lottery Data
fitness.sas src
[M] Data on physical fitness
fuel.sas src
[M] Fuel Consumption across the US
nations.sas src
[S] Nations data set
ozone.sas src
Maximum daily ozone concentrations
rubin.sas src
[M] 51 Properties of 125 words
sucrose.sas src
[1] Sucrose Data: Speed to traverse a Runway
treediam.sas src
[S] Tree Data from Weisberg.

Anova Project

The programs below illustrate some techniques for analyzing the Project 2 data. They are stored in the PROJECTS directory under PSY3030 (n:\psy3030\projects).
proj2glm.sas src
Constructing contrasts for Project 2 (5x4x2 design).
proj2gl2.sas src
Constructing contrasts for Project 2 (3x4x2 design).
proj2plt.sas src
Plotting means for Project 2
proj2pl2.sas src
Hi-resolution plots of means, using the %meanplot macro.
proj2pwr.sas src
Power computations for Main Effects in 3 x 4 x 2 Design
proj2pw2.sas src
Retrospective power analysis, using the output from PROC GLM to determine effect size in your data.

© 1995 Michael Friendly

Author: Michael Friendly