forked from friendly/SAS-macros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
catplot2.sas
97 lines (94 loc) · 2.67 KB
/
catplot2.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
%macro catplot(
data=_last_, /* out= data set from PROC CATMOD */
class=, /* variable for curves within each plot */
byvar=, /* plot for each level of by variables */
byfmt=, /* format for values of by variables */
x=, /* horizontal value for plot [NUMERIC] */
xc=, /* horizontal value for plot [CHAR] */
y=_pred_, /* ordinate for points (_pred_ or _obs_) */
type=FUNCTION,
z=1, /* std. error multiple for confidence intervals */
anno=, /* additional input annotate data set */
clfmt=, /* how to format values of class variable */
clside=last, /* side for labels of class var (FIRST|LAST) */
xfmt=, /* format for X variable */
posfmt=, /* format to translate class var to position */
vaxis=axis1,
haxis=axis2,
htext=1.4,
name=catplot)
;
%let class1=%scan(&class,1);
%let class2=%scan(&class,2);
%if &x ^= %str() %then %do;
%let px = &x;
%end;
%else %do;
%if &x ^= %str() %then %do;
%put CATPLOT: Either X= or XC= variable must be specified;
%goto DONE;
%end;
%let px = &xc;
%end;
proc summary data=&data nway;
class &byvar &class &px;
var _pred_;
where (_type_="&type");
output out=pred2 mean=_pred_;
proc sort;
by &byvar &class &px;
proc print;
id &byvar &class &px;
data anno2;
set pred2;
by &byvar &class1;
length text $20 function $8;
drop _type_ _freq_ _pred_ &class;
xsys='2'; ysys='2';
* style='DUPLEX';
size=&htext;
%if &x ^= %str() %then %do;
x = &x;
%end;
%else %do;
xc = &xc;
%end;
if &clside..&class1 then do;
y=_pred_;
text='00'x ||put(&class1,&clfmt) ||'00'x;
%if %upcase(&clside) = LAST %then %do;
position = '6';
%end;
%else %do;
position='4'; %end;
%if &posfmt ^= %str() %then %do;
position = put(&class,&posfmt);
%end;
function = 'LABEL'; output;
end;
%if &byvar ^= %str() %then %do;
goptions hby=0;
if first.&byvar then do;
xsys='1'; ysys='1';
x = 5; y=95; position='6';
text = put(&byvar,&byfmt);
function = 'LABEL'; output;
end;
%end;
*roc print;
%let ganno=;
%if &anno ^= %str() %then %do;
%let ganno=anno=&anno;
%end;
proc gplot data=pred2 &ganno;
format &px &xfmt;
plot &y * &px = &class
/ anno=anno2 frame nolegend
haxis=&haxis vaxis=&vaxis
hminor=0 vminor=1
name="&name";
%if &byvar ^= %str() %then %do;
by &byvar;
%end;
%done:
%mend;