Options ls=80 ps=60;
Title 'Sample Program';
Proc format;
Value sx 1 = 'female'
2 = 'male';
Value maj 1 = 'science'
2 = 'liberal arts'
3 = 'fine arts'
4 = 'business'
5 = 'pre-med'
6 = 'pre-law';
Value agp 1 = 'minor'
2 = 'adult';
Data One;
Input id 1-2 age 4-5 sex 7 major 9 grade 11 pretest 13
postest 15;
Label id = 'Respondent id'
Age = 'Age of Respondent in years'
Sex = 'Gender of Respondent'
Major = 'Field of Study'
Grade = 'Student year'
Pretest = 'Student pretest score'
Postest = 'Student Post-test score';
If sex = 1;
Diff = Postest - Pretest;
If age lt 21 then agegrp = 1;
else agegrp = 2;
format major maj.;
format sex sx.;
format agegrp agp.;
Cards;
01 23 1 1 4 2 9
02 34 2 3 4 5 9
03 35 1 2 4 3 8
04 19 2 4 2 5 9
05 20 1 4 3 4 8
06 21 2 5 4 3 7
Proc Print label;
Title2 'Listing of Data';
Run;
Proc Freq; Tables sex major ;
Title2 'Range Check: Percentage Tables of Sex & Major';
Run;
Proc univariate normal plot; var age;
Title2 'Univariate Analysis of Age';
Run;
Proc Corr; Var age grade;
title2 'Consistency check';
Run;
Options ls=80 ps=60;
Title 'Data Cleaning Preview';
Data One;
infile 'c:\tmp\datafile.dat';
Input id 1-2 age 4-5 sex 7 major 9 grade 11 pretest 13
postest 15;
input id age major sex;
Input fname $ 1-10 age;
If sex = 1;
if sex ne 2;
If age lt 21 then agegrp=1;
else agegrp = 2;
if age < 21 then agegrp eq 1;
else agegrp = 2;
gt greater than
= equal to
Proc format;
Value maj 1 = 'science'
2 = 'liberal arts'
3 = 'fine arts'
4 = 'business'
5 = 'pre-med'
6 = 'pre-law';
Value sx 1 = 'female'
2 = 'male';
format sex sx.;
If sex = 3 then sex = . ;
Age = 1995 - birthyear ;
Diff = Postest - Pretest;
Proc Corr;
Proc Corr Spearman;
run;
/* Discrete Variables can be examined with PROC CHART */
PROC CHART;
VBAR region/discrete;
run;
PROC CHART;
HBAR sex/discrete;
run;
/* Continuous Variables can be plotted */
PROC PLOT;
Plot GDP*time;
run;
PROC TIMEPLOT;
ID Month;
PLOT GDP;
run;
symbol1 i=join v=star c=green;
symbol2 i=join v=plus c=blue;
PROC GPLOT;
PLOT (GDP forecast) * time /overlay;
run;
/* A simple Frequencies Analysis of variables w, x and y */
PROC FREQ; Tables w x y;
run;
/* alternatively this may be invoked by the following command */
PROC FREQ; Tables w--y;
run;
/* A Crosstabulation of Discrete Variables x and y */
PROC FREQ; TABLES x*y/chisq;
run;
/* A Simple Means Analysis of variable z */
PROC MEANS; var age;
run;
/* A summary univariate analysis of varable age */
PROC UNIVARIATE normal plot; var age;
run;
/* An independent samples t-test of variable age by gender */
PROC TTEST;
class sex;
var age;
run;
/* A Paired-samples t-test of variable Diff is conducted */
PROC MEANS mean std stderr t prt;
Var Diff;
run;
/* A Pearson correlation between variables x & y */
PROC CORR; var x y;
run;
/* An Alpha Reliability Analysis of variables VV through YYY */
PROC CORR alpha; var VV--YYY;
run;
/* A One-Way Fixed Effects Means Model */
/* testing reading achievement by different teaching methods */
/* including test for homogeneity of variance and contrasts */
/* between levels */
PROC GLM;
class Method;
model readach = method/noint e;
means method/Hovtest=Levene(type=abs);
estimate 'L1' Method 1 -.5 -.5;
estimate 'L1 v L2' Method 1 -1 0;
estimate 'L1 v L3' Method 1 0 -1;
run;
or
PROC MIXED Cl Covtest;
class Method;
Model Readach = Method/DDFM=Satterth;
Repeated/GROUP=Method;
LSMeans Method/PDif=all adjust=Sidak;
run;
/* If Methods are a random sample of methods, then a random */
/* effects model can be used */
PROC GLM;
Class Method;
Model Readach = Method/SS1 SS2 SS3 SS4 e1 e2;
Random Method/Test;
LSMeans Method/PDiff=all Stderr adjust=bon;
run;
/* A Two-Way Treatment Structure with Unequal Variances */
/* Completely Randomized Block Design */
/* Source: "Examples for Analysis of Messy Data Mixed Models */
/* (1999). George A. Milliken and Dallas E. Johnson */
/* Dept of Statistics, Kansas State University, p.9 */
PROC MIXED;
Class Blk A B;
Model Y = A A*B/DDFM = Satterth;
Random Blk;
LSMeans A|B/Diff;
Repeated/Group=A*B;
run;
/* A Two-Way Treatment Structure Mixed Effects Model */
/* A is a fixed effect and B is a random effect */
PROC GLM;
Class A B;
Model Y = A B A*B/SS1 SS2 SS3 SS4 e;
Random B A*B/Test;
LSMeans A|B/adjust=bon;
run;
/* A full-factorial fixed Effects ANOVA of Y by SES and REGION */
PROC GLM;
class SEStype region;
model Y = SESTYPE|region/SS1 SS2 SS3 SS4;
means region/ tukey;
means region*SESTYPE/Scheffe;
OUTPUT OUT=RESDATA R=RESID1 P=PRED1;
run;
/* Testing the Residuals for Homogeneity */
PROC PLOT DATA=RESDATA;
plot RESID1*PRED1;
run;
/* Testing the Residuals for Normality */
PROC UNIVARIATE DATA=RESDATA normal plot;
Var resid1;
run;
/* If variances are found to be unequal, then */
/* PROC MIXED should be used */
PROC MIXED Cl Covtest;
class SEStype region;
model Y = SESTYPE|region/DDFM=Satterth;
repeated/Group=region*SESTYPE;
run;
/* An OLS Regression analysis of Y on X1,X2, and X3 */
/* with tests of assumptions */
PROC REG simple;
model Y = X1 X2 X3/ss1 ss2 corrb Stb Vif Collin Spec DW R;
OUTPUT OUT=RESDAT R=RESID P=PRED STUDENT=RSTD;
run;
/* Testing residual assumptions of the regression */
PROC PLOT DATA=RESDAT;
PLOT RSTD*PRED;
Title 'Examining Homogeneity of Residuals';
run;
PROC UNIVARIATE normal plot; VAR RESID;
run;
/* Logistic Regression Analysis where dependent variable (DV) */
/* is binary or dichotomous in coding */
/* Independent variables should be dummy coded or continuous */
PROC LOGISTIC Descending Ctable pprob=.5;
Model DV = X1 X2 X3 X4/
corrb aggregate scale=pearson lackfit rsquare iplots;
run;
This page has been accessed times. Counter courtesy of Web-Counter.
-
last updated 10 February 2000