全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1592 7
2012-07-15
不要对变量sort,然后取最大和最小的1%观测,我有很多变量,数据也很大,sort太慢。最好谁能给个宏程序,对任何变量都可以做的,求高手
二维码

扫码加我 拉你入群

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

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

全部回复
2012-7-16 09:13:13
data temp01;
        do id = 1 to 10000;
                v = ceil(rannor(0)*10);
                output;
        end;
run;

%macro data_sampling(var, top_or_bottom_flg, percent);
proc sql;
        drop table temp02;
        drop table temp03;
quit;
data _null_;
        set temp01 nobs=n;
        call symputx('n', max(1, floor(n*&percent.)) );
        stop;
run;
%do ii = 1 %to &n.;
        %if &ii. = 1 %then %do;
                data temp02(keep = a b);
                        retain a;
                        retain b;
                        set temp01 end=eof;
                        if _n_ = 1 then do;
                                a = id;
                                b = v;
                        end;else do;
                                %if "&top_or_bottom_flg." = "top" %then %do;
                                if b < v then do;
                                        a = id;
                                        b = v;
                                end;
                                %end;%else %do;
                                if b > v then do;
                                        a = id;
                                        b = v;
                                end;
                                %end;
                        end;
                        if eof then output;
                run;
                proc append base = temp03 data = temp02; run;
        %end;%else %do;
                data temp02(keep = a b);
                        retain a;
                        retain b;
                        if 0 then set temp03(keep = a);
                        if _n_ = 1 then do;
                                dcl hash h(dataset:"temp03");
                                h.definekey("a");
                                h.definedone();
                        end;
                        set temp01 end=eof;
                        if h.check(key:id) then do;
                                if _n_ = 1 then do;
                                        a = id;
                                        b = v;
                                end;else do;
                                        %if "&top_or_bottom_flg." = "top" %then %do;
                                        if b < v then do;
                                                a = id;
                                                b = v;
                                        end;
                                        %end;%else %do;
                                        if b > v then do;
                                                a = id;
                                                b = v;
                                        end;
                                        %end;
                                end;
                        end;
                        if eof then output;
                run;
                proc append base = temp03 data = temp02; run;
        %end;
%end;
%mend;

%data_sampling(var = v, top_or_bottom_flg = top, percent = 0.01);
二维码

扫码加我 拉你入群

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

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

2012-7-16 09:18:32
maidenhan 发表于 2012-7-16 09:13
data temp01;
        do id = 1 to 10000;
                v = ceil(rannor(0)*10);
你是以前写好的还是现写的?
二维码

扫码加我 拉你入群

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

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

2012-7-16 09:34:23
你的要求就是做winsorize处理
可以把双尾处指定观测赋值或删除
坛子里就有相关的宏
你搜搜看,可以直接用
二维码

扫码加我 拉你入群

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

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

2012-7-16 09:39:15
Imasasor 发表于 2012-7-16 09:18
你是以前写好的还是现写的?
今天早上写的
二维码

扫码加我 拉你入群

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

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

2012-7-16 09:46:54
maidenhan 发表于 2012-7-16 09:39
今天早上写的
太牛啦。
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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