全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1912 5
2014-09-14
悬赏 8 个论坛币 未解决
程序如下:(运行错误,求高手指导!)
%macro EqWBinn (DSin, XVar, Nb, XBVar, DSout, DSMap);
proc sql noprint;
        select max(&XVar) into: Vmax from &dsin;
        select min(&XVar) into: Vmin from &dsin;
run;
quit;

%let bs=%sysevalf((&Vmax-&Vmin)/&Nb);

data &dsout;
set &dsin;
        %do i=1 %to &Nb;
        %let Bin_U=%sysevalf(&Vmax+&Vmin);
        %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;

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;

%let DSin=sashelp.cars;
%let DSout=test1;
%let XVar=Horsepower;
%let Nb=428;
%let XBVar=Horsepower_b;
%let DSMap=test1map;

%EqWBinn(&DSin, &XVar, &Nb, &XBVar, &DSout, &DSMap);

proc chart data=test1;
vbar Horsepower_b;
run;


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-9-14 23:52:21
proc sql 没有run;
其他的太复杂,需要好好看
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-9-15 17:04:56
data 步里面不能用%let
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-9-19 03:03:49
Two things need to be attended as per below:
(1)  error
insert into &DSMap;
remove the ; at end
(2) logic problem
i bet the conditions in data-step should be associated with step &i. You need to think about the logic here.

JingJu
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2019-6-25 19:23:00
/*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;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2019-6-25 19:23:16
/*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;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群