Академический Документы
Профессиональный Документы
Культура Документы
str=crlf;
data _null_;
infile _ver end=_eof;
input name:$15. ver;
if upcase(name)="&sysmacroname" then do;
call symput("_newver",ver); stop;
end;
if _eof then call symput("_notfound",1);
run;
%if &syserr ne 0 or &_notfound=1 %then
%put &sysmacroname: Unable to check for newer version;
%else %if %sysevalf(&_newver > &_version) %then %do;
%put &sysmacroname: A newer version of the &sysmacroname macro is available.
;
%put %str(
) You can get the newer version at this location:;
%put %str(
) http://support.sas.com/ctx/samples/index.jsp;
%end;
%end;
%if &oneplot ne %then %let panel=N;
/* DATA= data set option must be specified and must exist */
%if &data= or %sysfunc(exist(&data)) ne 1 %then %do;
%put ERROR: DATA= data set not specified or not found.;
%goto exit;
%end;
/* RESPONSE= check */
%if &response= %then %do;
%put ERROR: The RESPONSE= parameter is required.;
%goto exit;
%end;
/* P= check */
%if &p= %then %do;
%put ERROR: The P= parameter is required.;
%goto exit;
%end;
/* EVENT= check */
%if &EVENT= %then %do;
%put ERROR: The EVENT= parameter is required.;
%goto exit;
%end;
/* GROUPS= check */
%if &groups ne 10 and &groups ne 20 %then %do;
%put ERROR: GROUPS= must be 10 or 20;
%goto exit;
%end;
/* GRID= check */
%if %upcase(&grid) ne ON and %upcase(&grid) ne OFF %then %do;
%put ERROR: GRID= must be ON or OFF;
%goto exit;
%end;
/* PANEL= check */
%if %upcase(%substr(&panel,1,1)) ne Y and
%upcase(%substr(&panel,1,1)) ne N %then %do;
%put ERROR: PANEL= must be YES or NO;
%goto exit;
%end;
/* GRAPH= check */
%if %upcase(%substr(&graph,1,1)) ne L and
%upcase(%substr(&graph,1,1)) ne B and
_xvar=_grp;
_xvar=SelectedPct;
_xvar=Percentile;
or SELECTEDPCT;
CumEvntCnt+EvntCnt;
CumGrpCnt+_freq_;
/* Percent Response */
PctResp=100*EvntProp;
BasePctResp=TotEvntPct;
/* Cumulative Percent Response */
if CumGrpCnt=0 then CumPctResp=0; else
CumPctResp=100*(CumEvntCnt/CumGrpCnt);
BaseCumPctResp=TotEvntPct;
/* Percent Captured */
PctCaptured=100*(EvntCnt/TotEvntCnt);
BasePctCaptured=100*_freq_/NObs;
/* Cumulative Percent Captured */
CumPctCaptured=100*(CumEvntCnt/TotEvntCnt);
BaseCumPctCaptured=100*CumGrpCnt/NObs;
/* Lift */
Lift=PctResp/TotEvntPct;
BaseLift=1;
/* Cumulative Lift */
CumLift=CumPctResp/TotEvntPct;
BaseCumLift=1;
/* Gain */
Gain=100*(Lift-1);
BaseGain=0;
/* Cumulative Gain */
CumGain=100*(CumLift-1);
BaseCumGain=0;
drop _type_;
end;
label selectedpct="Selected Percent"
CumLift="Cumulative Lift"
PctCaptured="Percent Captured"
_grp="Group"
;
run;
%if %upcase(%substr(&graph,1,1))=N %then %goto exit;
proc template;
define statgraph GainLiftPanel;
mvar _xvar;
begingraph / designheight=defaultdesignwidth;
entrytitle "Gains and Lift Plots" / pad=(bottom=10);
layout lattice / rows=4 columns=2 columndatarange=union;
column2headers;
entry textattrs=(weight=bold)
entry textattrs=(weight=bold)
endcolumn2headers;
rowheaders;
entry textattrs=(weight=bold)
entry textattrs=(weight=bold)
entry textattrs=(weight=bold)
"Cumulative";
"NonCumulative";
"Gain";
"Lift";
'%Captured';
*Row 3;
layout overlay / yaxisopts=(display=(line ticks tickvalues)
griddisplay=&grid);
%if %upcase(%substr(&graph,1,1))=L %then %do;
seriesplot y=BaseCumPctCaptured x=_xvar / lineattrs=GraphData2;
seriesplot y=CumPctCaptured
x=_xvar / lineattrs=GraphData1;
%end;
%else %do;
barchartparm y=CumPctCaptured
x=_xvar;
seriesplot y=BaseCumPctCaptured x=_xvar / lineattrs=GraphData2;
%end;
endlayout;
layout overlay / yaxisopts=(display=(line ticks tickvalues)
griddisplay=&grid);
%if %upcase(%substr(&graph,1,1))=L %then %do;
seriesplot y=BasePctCaptured x=_xvar / lineattrs=GraphData2;
seriesplot y=PctCaptured
x=_xvar / lineattrs=GraphData1;
%end;
%else %do;
barchartparm y=PctCaptured
x=_xvar;
seriesplot y=BasePctCaptured x=_xvar / lineattrs=GraphData2;
%end;
endlayout;
*Row 4;
layout overlay / yaxisopts=(display=(line ticks tickvalues)
griddisplay=&grid);
%if %upcase(%substr(&graph,1,1))=L %then %do;
seriesplot y=BaseCumPctResp x=_xvar / lineattrs=GraphData2;
seriesplot y=CumPctResp
x=_xvar / lineattrs=GraphData1;
%end;
%else %do;
barchartparm y=CumPctResp
x=_xvar;
seriesplot y=BaseCumPctResp x=_xvar / lineattrs=GraphData2;
%end;
endlayout;
layout overlay / yaxisopts=(display=(line ticks tickvalues)
griddisplay=&grid);
%if %upcase(%substr(&graph,1,1))=L %then %do;
seriesplot y=BasePctResp x=_xvar / name="Baseline" legendlabel="
Baseline" lineattrs=GraphData2;
seriesplot y=PctResp
x=_xvar / lineattrs=GraphData1;
%end;
%else %do;
barchartparm y=PctResp
x=_xvar;
seriesplot y=BasePctResp x=_xvar / name="Baseline" legendlabel="
Baseline" lineattrs=GraphData2;
%end;
endlayout;
sidebar;
discretelegend "Baseline" ;
endsidebar;
endlayout;
endgraph;
end;
run;
proc template;
define statgraph GainLiftPlot;
mvar _title _yvar _xvar _baseline;
begingraph;
entrytitle _title;
layout overlay / xaxisopts=(griddisplay=&grid)
yaxisopts=(display=(line ticks tickvalues) griddisplay=&grid);
%if %upcase(%substr(&graph,1,1))=L %then %do;
seriesplot y=_baseline x=_xvar / name="Baseline" legendlabel="Basel
ine" lineattrs=GraphData2;
seriesplot y=_yvar
x=_xvar / lineattrs=GraphData1;
%end;
%else %do;
barchartparm y=_yvar
x=_xvar;
seriesplot y=_baseline x=_xvar / name="Baseline" legendlabel="Basel
ine" lineattrs=GraphData2;
%end;
discretelegend "Baseline";
endlayout;
endgraph;
end;
run;
/* Panel of plots requested */
%if %upcase(%substr(&panel,1,1))=Y %then %do;
proc sgrender data=&out template=GainLiftPanel;
run;
%end;
/* Specific plot requested */
%else %if &oneplot ne %then %do;
%oneplot(&oneplot)
%end;
/* All plots, unpaneled, requested */
%else %do;
%oneplot(CG)
%oneplot(GA)
%oneplot(CL)
%oneplot(LI)
%oneplot(CC)
%oneplot(PC)
%oneplot(CR)
%oneplot(PR)
%end;
%exit:
options &_opts;
%mend GainLift;