📄 sdplot.sas
字号:
%macro SDPLOT;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* LAST MODIFIED: June 15, 2000 */
/* */
/* Use PROC GPLOT to get "Standard Deviation plots" of the */
/* residual vs. the categorical predictors. */
/* */
/* a. Use the residuals created in SCATPLOT. */
/* */
/* b. Plot the variables. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
goptions reset=ALL
cback=white
htitle=5
htext=3
ftext=swissb
colors=(black)
gunit=pct
border
rotate=landscape
NOdisplay
%if &SYSSCP eq WIN %then
%do;
device=WIN
%end;
%else %do;
device=XCOLOR
%end;
;
/* PLOT RESIDUALS VS PREDICTORS... */
/* NOTE: WORK.MERGED1 WAS CREATED BY SCATPLOT.SAS... */
%if %length(&CATPREDS) GT 0 %then
%do;
%macro COUNTCAT;
%let COUNT=0;
%if &CATPREDS NE %then
%do;
%let WORD=%scan(&CATPREDS,1);
%do %while(&WORD NE );
%let COUNT=%eval(&COUNT+1);
%let WORD=%scan(&CATPREDS,&COUNT+1);
%end;
%end;
&COUNT
%mend COUNTCAT;
%do i=1 %to %COUNTCAT;
%let var&i=%scan(&CATPREDS,&i);
/* %if %length(&&VAR&i) eq 8 %then
%let var&i=%substr(&&VAR&i,1,%eval(%length(&&VAR&i)-1));
*/
proc means data=WORK.MERGED1 mean std noprint ;
var RESID;
class &&VAR&i;
output out=WORK.&&VAR&i
mean=VAR&i.MN
std=VAR&i.STD
;
run;
proc means data=WORK.&&VAR&i max min noprint ;
var VAR&i.MN VAR&i.STD;
output out=WORK.X&&VAR&i
max=MEANMAX STDMAX
min=MEANMIN STDMIN
;
run;
data _null_ ;
set WORK.X&&VAR&i ;
call symput
("U&&VAR&i",trim(left(ceil(MEANMAX+(2*STDMAX)))))
;
call symput
("L&&VAR&i",trim(left(floor(MEANMIN-(2*STDMAX)))))
;
RANGE=(abs(resolve('&&&&L&&VAR&i'))
+abs(resolve('&&&&U&&VAR&i')))
;
INCREMNT=round((RANGE/10),0.1);
if (INCREMNT GE 0 and INCREMNT LT 1) then
INCREMNT=round((INCREMNT), 0.1);
if (INCREMNT GE 1 and INCREMNT LT 10) then
INCREMNT=round((INCREMNT), 1.0);
if (INCREMNT GE 10 and INCREMNT LT 100) then
INCREMNT=round((INCREMNT), 10.0);
if (INCREMNT GE 100 and INCREMNT LT 1000) then
INCREMNT=round((INCREMNT),100.0);
if (INCREMNT GE 1000 and INCREMNT LT 10000) then
INCREMNT=round((INCREMNT),1000.0);
if (INCREMNT GT 0 or INCREMNT LT 0) then
call symput("I&&VAR&i",trim(left(INCREMNT)));
else if INCREMNT EQ 0 then
call symput("I&&VAR&i",trim(left(0.1)));
run;
symbol1 value=none
interpol=STD1T /* 1 std dev (def.=2) draw TOP. */
mode=include /* incl values outside axes. */
;
/* axis1&i is the vertical axis... */
axis1&i label=("Residuals")
order=&&&&L&&VAR&i to &&&&U&&VAR&i by &&&&I&&VAR&i
;
/* axis2&i is the horizontal axis... */
axis2&i label=("&&VAR&i")
offset=(3,3)
;
proc gplot data=WORK.MERGED1
gout=WORK.SDPLTCAT
;
plot RESID * &&VAR&i
/ frame vaxis=AXIS1&i haxis=AXIS2&i vref=0
name="CATPRE&i";
title1 "Plot of Residuals vs. Categorical Predictors";
/* NOTE: FOOTNOTES NOT INDENTED TO KEEP TEXT ON ONE LINE. */
footnote1 "Plot of Residuals restricted to +/- 1 Std. Dev.";
footnote2 "Scale of Vertical Axis restricted to +/- 2 Std. Dev.";
run;
quit;
proc datasets lib=WORK nolist;
delete &&VAR&i X&&VAR&i ;
run;
quit;
%end;
%end;
/* COUNT NUMBER OF GRAPHS, ASSIGN TO GLOBAL MACRO VARIABLE. */
proc catalog cat=WORK.SDPLTCAT;
contents out=WORK.SDPLTCON;
run;
quit;
data _NULL_ ;
set WORK.SDPLTCON end=LAST ;
%global COUNTSD;
if LAST eq 1 then call symput("COUNTSD",trim(left(_N_)));
run;
/* GENERATE MAIN TITLES WITH GSLIDE... */
proc gslide gout=WORK.SDPLTCAT name='STDSLIDE';
title1 "Regression Diagnostic Plots";
title2 "Standard Deviation Plots";
footnote1;
run;
quit;
/* MORE HOUSECLEANING: DELETE REMAINING TEMPORARY DATASETS */
/* DELETE MACROS FROM SASMACR CATALOG. */
/* NOTE: KEEP WORK.MERGED1, IT IS NEEDED BY HISTOGRM.SAS. */
proc datasets lib=WORK nolist;
delete SDPLTCON ;
run;
quit;
proc catalog cat=WORK.SASMACR;
delete COUNTCAT / entrytype=macro;
run;
quit;
%mend SDPLOT;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -