Dear,
I used the code from Rick Wicklin to produce a funnel plot which works really nice. However, In addition I have a grouping variable for which I used a format, but I can't get the order correct of the legend. This is my code (I use SAS 9.4):
proc sort data = &lib..Funnel out = sortfunnel;
by mycap;
run;
/*--Make control data set for format--*/
data myfmt;
set sortfunnel;
by mycap;
if first.mycap then do;
fmtname='typefmt';
start=mycap;
label=label;
output;
end;
run;
data myfmt (keep=fmtname start label mycap);
set myfmt ;
if start=. then delete;
run;
/*--Create format--*/
proc format cntlin=myfmt;
run;
/* 4. Plot proportions versus sample size. Overlay control limits */
ods rtf file = "&path.funnelplot.rtf" style=analysis;
options orientation=landscape;
title "My Title";
proc sgplot data=&lib..Funnel NOCYCLEATTRS ;
styleattrs datacontrastcolors=(LILG BILG STLG VILG DELG) ;
band x=N lower=L3sd upper=U3sd / nofill lineattrs=(color=lipk) legendlabel="99.8% limits" name="band99";
band x=N lower=L2sd upper=U2sd / nofill lineattrs=(color=gray) legendlabel="95% limits" name="band95";
refline &AvgProp / axis=y lineattrs=(pattern=longdash color=blue);
scatter x=Trials y=Proportion / group = mycap
markerattrs=(symbol=circlefilled size=5 )
legendlabel="capaciteit" name="cap";
keylegend "band95" "band99" / location=inside position=bottomright;
keylegend "cap" / location=inside position=right title='capaciteit';
yaxis grid values=(0 to 1 by 0.1) label = "tekst voor Y-as";
xaxis grid label = "tekst voor X-as";
format mycap typefmt.;
run;
ods rtf close;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.