/*EqWBin..........................*/
%macro eqwbinn (dsin,xvar,nb,xbvar,dsout,dsmap);
/*extract max and min values */
proc sql noprint;
select max(&xvar) into :vmax from &dsin;
select min(&xvar) into :vmin from &dsin;
run;quit;
/*calculate the bin size*/
%let bs =%sysevalf((&vmax-&vmin)/&nb);
/*loop on each of the values,create the bin boundaries,and count the
number of values in each bin*/
data &dsout;
set &dsin;
%do i=1 %to &nb;
%let
bin_u=%sysevalf(&vmin+&i*&bs);
%let bin_l=%sysevalf(&bin_u-&bs);
%if &i=1 %then %do;
%if &xvar>=&bin_l and &xvar<=&bin_u %then &xbvar=&i;
%end;
%else %if &i>1 %then %do;
if &xvar>&bin_l and &xvar<=&bin_u then &xbvar=&i;
%end;
%end;
run;
/* create the binning map and store the bin boundaries*/
proc sql noprint;
create table &dsmap (binmin num,binmax num,binno num);
%do i=1 %to &nb;
%let
bin_u=%sysevalf(&vmin+&i*&bs);
%let
bin_l=%sysevalf(&bin_u-&bs);
insert into &dsmap
values(&bin_l,&bin_u,&i);
%end;
quit;
%mend;
|