www.sas.com > Service and Support > Technical Support
 
Technical Support SAS - The power to know(tm)
  TS Home | Intro to Services | News and Info | Contact TS | Site Map | FAQ | Feedback

  

/****************************************************************/
/* SAS SAMPLE LIBRARY */
/* */
/* NAME: REGEX */
/* TITLE: Documentation Examples for PROC REG */
/* PRODUCT: STAT */
/* SYSTEM: ALL */
/* KEYS: regression */
/* PROCS: REG */
/* DATA: */
/* */
/* REF: SAS/STAT GUIDE: PROC REG CHAPTER */
/* MISC: */
/* */
/****************************************************************/

/* Data used in the following examples */
data class;
input name $ height weight age;
cards;
Alfred 69.0 112.5 14
Alice 56.5 84.0 13
Barbara 65.3 98.0 13
Carol 62.8 102.5 14
Henry 63.5 102.5 14
James 57.3 83.0 12
Jane 59.8 84.5 12
Janet 62.5 112.5 15
Jeffrey 62.5 84.0 13
John 59.0 99.5 12
Joyce 51.3 50.5 11
Judy 64.3 90.0 14
Louise 56.3 77.0 12
Mary 66.5 112.0 15
Philip 72.0 150.0 16
Robert 64.8 128.0 12
Ronald 67.0 133.0 15
Thomas 57.5 85.0 11
William 66.5 112.0 15
;
data fitness;
input age weight oxy runtime rstpulse runpulse maxpulse;
cards;
44 89.47 44.609 11.37 62 178 182
40 75.07 45.313 10.07 62 185 185
44 85.84 54.297 8.65 45 156 168
42 68.15 59.571 8.17 40 166 172
38 89.02 49.874 9.22 55 178 180
47 77.45 44.811 11.63 58 176 176
40 75.98 45.681 11.95 70 176 180
43 81.19 49.091 10.85 64 162 170
44 81.42 39.442 13.08 63 174 176
38 81.87 60.055 8.63 48 170 186
44 73.03 50.541 10.13 45 168 168
45 87.66 37.388 14.03 56 186 192
45 66.45 44.754 11.12 51 176 176
47 79.15 47.273 10.60 47 162 164
54 83.12 51.855 10.33 50 166 170
49 81.42 49.156 8.95 44 180 185
51 69.63 40.836 10.95 57 168 172
51 77.91 46.672 10.00 48 162 168
48 91.63 46.774 10.25 48 162 164
49 73.37 50.388 10.08 67 168 168
57 73.37 39.407 12.63 58 174 176
54 79.38 46.080 11.17 62 156 165
52 76.32 45.441 9.63 48 164 166
50 70.87 54.625 8.92 48 146 155
51 67.25 45.118 11.08 48 172 172
54 91.63 39.203 12.88 44 168 172
51 73.71 45.790 10.47 59 186 188
57 59.08 50.545 9.93 49 148 155
49 76.32 48.673 9.40 56 186 188
48 61.24 47.920 11.50 52 170 176
52 82.78 47.467 10.50 53 170 172
;
data uspop;
input pop @@;
retain year 1780;
year=year+10;
yearsq=year*year;
pop=pop/1000;
cards;
3929 5308 7239 9638 12866 17069 23191 31443 39818 50155
62947 75994 91972 105710 122775 131669 151325 179323 203211
. . .
;
/* Introduction */
/* Output 28.1 */
proc reg data=class;
model weight = height;
plot weight*height;
/* Input Data Set */
/* Output 28.2 */
proc corr data=fitness outp=r;
var oxy runtime age weight runpulse maxpulse rstpulse;
proc print data=r;
/* Output 28.3 */
proc reg data=r;
model oxy=runtime age weight;
/* Output 28.4 */
proc reg data=fitness outsscp=sscp noprint;
model oxy=runtime age weight runpulse maxpulse rstpulse;
proc print data=sscp;
proc reg data=sscp;
model oxy=runtime age weight;
/* Output Data Set */
/* Output 28.5 */
proc reg data=uspop outest=est;
m1: model pop=year;
m2: model pop=year yearsq;
proc print data=est;
/* Output 28.6 */
proc reg data=fitness outest=est;
model oxy=age weight runtime runpulse rstpulse maxpulse
/ selection=rsquare mse jp gmsep cp aic bic sbc b best=1;
/* Output 28.7 */
proc print data=est;
/* Output 28.8 */
proc reg data=fitness outsscp=sscp;
var oxy runtime age weight rstpulse runpulse maxpulse;
proc print data=sscp;
/* Interactive Analysis */
/* Output 28.9 */
proc reg data=class;
model weight = age height;
run;
/* Output 28.10 */
delete age;
print;
run;
/* Output 28.11 */
add age;
plot r.*p.;
run;
/* Output 28.12 */
reweight r.>20;
plot;
run;

/* ---Parameter Estimates and Associated Statistics--- */
/* Output 28.13 */
proc reg data=fitness;
model oxy=runtime age weight runpulse maxpulse rstpulse
/ ss1 ss2 stb covb corrb;
/* Output 28.14 */
proc reg data=uspop;
id year;
model pop=year yearsq / p r cli clm;

/* ----------------------------------------------------------- */
/* See the program regplot.sas for examples in the section of */
/* Producing Scatter Plots. */
/* ----------------------------------------------------------- */

/* ---Painting Scatter Plots--- */
/* Output 28.20 */
proc reg data=class;
model weight=age height / noprint;
plot student.*p.;
run;
/* Output 28.21 */
paint name='Henry' / symbol='H';
plot;
run;
/* Output 28.22 */
paint student.>=2 or student.<=-2 / symbol='$';
plot;
run;
/* Output 28.23 */
paint student.>=1 / symbol='p';
paint student.<1 and student.>-1 / symbol='s';
paint student.<=-1 / symbol='n';
plot student.*p. cookd.*h. / hplots=2;

/* Models of Less Than Full Rank */
/* Ouptut 28.24 */
data fit2;
set fitness;
dif=runpulse-rstpulse;
proc reg data=fit2;
model oxy=runtime age weight runpulse maxpulse rstpulse dif;

/* Collinearity Diagnostics */
/* Output 28.25 */
proc reg data=fitness;
model oxy=runtime age weight runpulse maxpulse rstpulse
/ tol vif collin;
/* Influence Diagnostics */
/* Output 28.26 */
proc reg data=uspop;
model pop=year yearsq / influence;

/* Partial Regression Residual Plot */
/* Output 28.27 */
proc reg data=fitness;
model oxy=runtime weight age / partial;

/* ------------------------------------------------------------- */
/* See the program reweight.sas for examples in the section of */
/* Reweighting Observations in an Analysis. */
/* ------------------------------------------------------------- */

/* Multivariate Tests */
/* Output 28.34 */
* Manova Data from Morrison's Multivariate Text, 2nd Edition, Page 190;
data a;
input sex $ drug $ @;
do rep=1 to 4;
input y1 y2 @;
output;
end;
cards;
m a 5 6 5 4 9 9 7 6
m b 7 6 7 7 9 12 6 8
m c 21 15 14 11 17 12 12 10
f a 7 10 6 6 9 7 8 10
f b 10 13 8 7 7 6 6 9
f c 16 12 14 9 14 8 10 5
;
data b;
set a;
sexcode=(sex='m')-(sex='f');
drug1=(drug='a')-(drug='c');
drug2=(drug='b')-(drug='c');
sexdrug1=sexcode*drug1;
sexdrug2=sexcode*drug2;
proc reg;
model y1 y2=sexcode drug1 drug2 sexdrug1 sexdrug2;
y1y2drug: mtest y1=y2, drug1,drug2;
drugshow: mtest drug1, drug2 /print canprint;

/* Autocorrelation in Time Series Data */
/* Output 28.35 */
proc reg data=uspop;
model pop=year yearsq / dw;

/* ---Example 1: Population Growth Trends--- */
/* Output 28.36 */
proc reg data=uspop;
var yearsq;
model pop=year / r cli clm;
plot r.*p.;
add yearsq;
print;
plot;
/* Output 28.37 */
plot pop*year='a' predicted.*year='p' u95.*year='u'
l95.*year='1' /overlay;

/* ---Example 2: Aerobic Fitness Prediction--- */
/* Output 28.38 */
proc reg data=fitness;
model oxy=age weight runtime runpulse rstpulse maxpulse
/ selection=forward;
/* Output 28.39 */
model oxy=age weight runtime runpulse rstpulse maxpulse
/ selection=backward;
/* Output 28.40 */
model oxy=age weight runtime runpulse rstpulse maxpulse
/ selection=maxr;
/* Output 28.41 */
model oxy=age weight runtime runpulse rstpulse maxpulse
/ selection=rsquare cp;

/* ---Example 3: Predicting Weight by Height and Age--- */
/* Output 28.42 */
data htwt;
input sex $ age :3.1 height weight @@;
cards;
f 143 56.3 85.0 f 155 62.3 105.0 f 153 63.3 108.0 f 161 59.0 92.0
f 191 62.5 112.5 f 171 62.5 112.0 f 185 59.0 104.0 f 142 56.5 69.0
f 160 62.0 94.5 f 140 53.8 68.5 f 139 61.5 104.0 f 178 61.5 103.5
f 157 64.5 123.5 f 149 58.3 93.0 f 143 51.3 50.5 f 145 58.8 89.0
f 191 65.3 107.0 f 150 59.5 78.5 f 147 61.3 115.0 f 180 63.3 114.0
f 141 61.8 85.0 f 140 53.5 81.0 f 164 58.0 83.5 f 176 61.3 112.0
f 185 63.3 101.0 f 166 61.5 103.5 f 175 60.8 93.5 f 180 59.0 112.0
f 210 65.5 140.0 f 146 56.3 83.5 f 170 64.3 90.0 f 162 58.0 84.0
f 149 64.3 110.5 f 139 57.5 96.0 f 186 57.8 95.0 f 197 61.5 121.0
f 169 62.3 99.5 f 177 61.8 142.5 f 185 65.3 118.0 f 182 58.3 104.5
f 173 62.8 102.5 f 166 59.3 89.5 f 168 61.5 95.0 f 169 62.0 98.5
f 150 61.3 94.0 f 184 62.3 108.0 f 139 52.8 63.5 f 147 59.8 84.5
f 144 59.5 93.5 f 177 61.3 112.0 f 178 63.5 148.5 f 197 64.8 112.0
f 146 60.0 109.0 f 145 59.0 91.5 f 147 55.8 75.0 f 145 57.8 84.0
f 155 61.3 107.0 f 167 62.3 92.5 f 183 64.3 109.5 f 143 55.5 84.0
f 183 64.5 102.5 f 185 60.0 106.0 f 148 56.3 77.0 f 147 58.3 111.5
f 154 60.0 114.0 f 156 54.5 75.0 f 144 55.8 73.5 f 154 62.8 93.5
f 152 60.5 105.0 f 191 63.3 113.5 f 190 66.8 140.0 f 140 60.0 77.0
f 148 60.5 84.5 f 189 64.3 113.5 f 143 58.3 77.5 f 178 66.5 117.5
f 164 65.3 98.0 f 157 60.5 112.0 f 147 59.5 101.0 f 148 59.0 95.0
f 177 61.3 81.0 f 171 61.5 91.0 f 172 64.8 142.0 f 190 56.8 98.5
f 183 66.5 112.0 f 143 61.5 116.5 f 179 63.0 98.5 f 186 57.0 83.5
f 182 65.5 133.0 f 182 62.0 91.5 f 142 56.0 72.5 f 165 61.3 106.5
f 165 55.5 67.0 f 154 61.0 122.5 f 150 54.5 74.0 f 155 66.0 144.5
f 163 56.5 84.0 f 141 56.0 72.5 f 147 51.5 64.0 f 210 62.0 116.0
f 171 63.0 84.0 f 167 61.0 93.5 f 182 64.0 111.5 f 144 61.0 92.0
f 193 59.8 115.0 f 141 61.3 85.0 f 164 63.3 108.0 f 186 63.5 108.0
f 169 61.5 85.0 f 175 60.3 86.0 f 180 61.3 110.5 m 165 64.8 98.0
m 157 60.5 105.0 m 144 57.3 76.5 m 150 59.5 84.0 m 150 60.8 128.0
m 139 60.5 87.0 m 189 67.0 128.0 m 183 64.8 111.0 m 147 50.5 79.0
m 146 57.5 90.0 m 160 60.5 84.0 m 156 61.8 112.0 m 173 61.3 93.0
m 151 66.3 117.0 m 141 53.3 84.0 m 150 59.0 99.5 m 164 57.8 95.0
m 153 60.0 84.0 m 206 68.3 134.0 m 250 67.5 171.5 m 176 63.8 98.5
m 176 65.0 118.5 m 140 59.5 94.5 m 185 66.0 105.0 m 180 61.8 104.0
m 146 57.3 83.0 m 183 66.0 105.5 m 140 56.5 84.0 m 151 58.3 86.0
m 151 61.0 81.0 m 144 62.8 94.0 m 160 59.3 78.5 m 178 67.3 119.5
m 193 66.3 133.0 m 162 64.5 119.0 m 164 60.5 95.0 m 186 66.0 112.0
m 143 57.5 75.0 m 175 64.0 92.0 m 175 68.0 112.0 m 175 63.5 98.5
m 173 69.0 112.5 m 170 63.8 112.5 m 174 66.0 108.0 m 164 63.5 108.0
m 144 59.5 88.0 m 156 66.3 106.0 m 149 57.0 92.0 m 144 60.0 117.5
m 147 57.0 84.0 m 188 67.3 112.0 m 169 62.0 100.0 m 172 65.0 112.0
m 150 59.5 84.0 m 193 67.8 127.5 m 157 58.0 80.5 m 168 60.0 93.5
m 140 58.5 86.5 m 156 58.3 92.5 m 156 61.5 108.5 m 158 65.0 121.0
m 184 66.5 112.0 m 156 68.5 114.0 m 144 57.0 84.0 m 176 61.5 81.0
m 168 66.5 111.5 m 149 52.5 81.0 m 142 55.0 70.0 m 188 71.0 140.0
m 203 66.5 117.0 m 142 58.8 84.0 m 189 66.3 112.0 m 188 65.8 150.5
m 200 71.0 147.0 m 152 59.5 105.0 m 174 69.8 119.5 m 166 62.5 84.0
m 145 56.5 91.0 m 143 57.5 101.0 m 163 65.3 117.5 m 166 67.3 121.0
m 182 67.0 133.0 m 173 66.0 112.0 m 155 61.8 91.5 m 162 60.0 105.0
m 177 63.0 111.0 m 177 60.5 112.0 m 175 65.5 114.0 m 166 62.0 91.0
m 150 59.0 98.0 m 150 61.8 118.0 m 188 63.3 115.5 m 163 66.0 112.0
m 171 61.8 112.0 m 162 63.0 91.0 m 141 57.5 85.0 m 174 63.0 112.0
m 142 56.0 87.5 m 148 60.5 118.0 m 140 56.8 83.5 m 160 64.0 116.0
m 144 60.0 89.0 m 206 69.5 171.5 m 159 63.3 112.0 m 149 56.3 72.0
m 193 72.0 150.0 m 194 65.3 134.5 m 152 60.8 97.0 m 146 55.0 71.5
m 139 55.0 73.5 m 186 66.5 112.0 m 161 56.8 75.0 m 153 64.8 128.0
m 196 64.5 98.0 m 164 58.0 84.0 m 159 62.8 99.0 m 178 63.8 112.0
m 153 57.8 79.5 m 155 57.3 80.5 m 178 63.5 102.5 m 142 55.0 76.0
m 164 66.5 112.0 m 189 65.0 114.0 m 164 61.5 140.0 m 167 62.0 107.5
m 151 59.3 87.0
;
title '-------- Data on age, weight, and height of children -----';
proc reg outest=est1 outsscp=sscp1;
by sex;
eq1: model weight=height;
eq2: model weight=height age;
proc print data=sscp1;
title2 'SSCP type data set';
proc print data=est1;
title2 'EST type data set';
run;

Copyright (c) 2002 SAS Institute Inc. All Rights Reserved.
Terms of Use & Legal Information | Privacy Statement