OPTIONS LS=70 NODATE; /* This program will generate the output necessary for analysis of the weight gain data from parts of problems 10.3, 6, 11, 15, 19, and 29 These problems pertain to a dataset in which weightgains (y) for mothers during pregnancy are regressed on age (x). */ DATA wtgains; INPUT x y; label y="weightgain"; label x="age"; /* 1) last two observations have missing response values 2) CARDS; tells SAS to find data just below. */ CARDS; 24 17.17 22 10.34 16 7.04 17 6.91 19 7.56 15 6.32 21 13.01 23 13.80 18 . 35 . ; /*the command below can be used to control where graphics files go - put a star in front to ignore it */ *GOPTIONS DEVICE=PSLEPSF COLORS=(BLACK) GSFMODE=REPLACE; /*PROC GPLOT DATA=wtgains; TITLE "y versus x (scatterplot)"; PLOT y*x; RUN;*/ /* In PROC REG, 1) SIMPLE reports summary stats for y, x 2) CLB reports 95% confidence intervals for beta0, beta1 3) XPX reports the matrix product t(X) * X 4a) PRED=p requests that predicted or fitted values be written to 4b) a variable called "p" in the new temporary SAS dataset "two" 4c) R=r requests residuals be written to the variable called "r" 4d) L95M and U95M request confidence limits for the mean at each observed x 4e) STDP gives the standard error of the estimated mean at each observed x 4f) L95 and U95 request prediction limits for an individual at each observed x 4g) the PLOT command generates some nice plots */ PROC REG DATA=wtgains SIMPLE; MODEL y=x/CLB XPX P CLI CLM; OUTPUT OUT=resids PRED=p R=r L95M=lcb U95M=ucb L95=lpb U95=upb STDP=stdmean; PLOT (RESIDUAL. y)*x; RUN; PROC PRINT DATA=two;RUN; /* just prints the dataset "two" */ /* some residual plots if you want them: */ PROC GPLOT DATA=resids; TITLE "y versus x (scatterplot)"; PLOT y*x; RUN; PROC GPLOT DATA=resids; TITLE "Residuals v predicted"; PLOT r*p; RUN; PROC PLOT DATA=resids; TITLE "Residuals v x"; PLOT r*x; RUN; /* change of scale problem below */ DATA wtgains2; SET wtgains; ynew=y*2.2; xnew=x*12; LABEL ynew="wt gain in lbs"; LABEL xnew="age in months"; RUN; PROC REG SIMPLE; MODEL ynew=xnew; PLOT ynew*xnew; * plots may also be generated within PROC REG; RUN;