小弟是SAS新手,对下面标洋红色的这段SAS宏代码不是很理解,请高手帮忙指点一下,谢谢!
%macro OneContPlot(data=dsname,x=x,y=y,numy=3,const=0.5,nbhd=50,plot=1);
/*--------------------------------------------------------------------------
A macro extension of SAS Usage Note 37944 to continuous covariates. Plots
the empirical logits defined using the NBHD/2 observed X values preceding
and following each observation against the levels of a single continuous
var, then smooths the result. Called by the %EmpiricalLogitPlot macro.
data= name of the input data set.
x= name of the single continuous covariate.
y= name of the response variable. y=1,2,3...
numy= number of levels of the response.
const= small value in case of zero cells.
nbhd= total number of neighbors.
plot= 1=create the plot
--------------------------------------------------------------------------*/
ods graphics / antialiasmax=100000;
data temp;
set &data;
proc sort data=temp;
by &x &y;
%let Full=%eval(&nbhd);
%let Fullp1=%eval(&nbhd+1);
%let Half=%eval(&nbhd/2);
%let numym1=%eval(&numy-1);
data temp2;
set temp;
retain %do i=1 %to &numy; sum&i %end; 0;
lagx= lag&Full(&x);
lagHalfx=lag&Half(&x);
lagy=lag&Fullp1(&y);
%do i=1 %to &numy; sum&i=sum&i+(&y=&i); %end;
if (lagy^=.) then do;
%do i=1 %to &numy; sum&i=sum&i-(lagy=&i); %end;
end;
data temp;
set temp2;
if (_n_<&Full) then delete;
data temp2;
set temp;
const=%sysevalf(&const+0);
x=lagHalfx;
group="&x";
%do i=1 %to &numym1; %let j=%eval(&i+1);
d&i=log((sum(of sum1-sum&i)+const) / (sum(of sum&j-sum&numy)+const));
%end;
keep d1-d&numym1 group x;
run;
%if %eval(&plot eq 1) %then %do;
proc sgplot;
%do i=1 %to &numym1;
loess y=d&i x=x / smooth=0.2 legendlabel="Pr(&y<=&i)"
lineattrs=GraphData&i(thickness=3px)
markerattrs=(color=gray);
%end;
yaxis values=(-5 to 5) label="Cumulative Probability";
keylegend %do i=1 %to &numym1; "series&i" %end;;
run;
%end;
%mend;