微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我如何使用 Do 循环或其他东西来自动执行此操作? SAS

如何解决我如何使用 Do 循环或其他东西来自动执行此操作? SAS


proc sql;

create table MMx
as select distinct a.*,b.max_days_late as max_LD_1,case 
        when b.max_days_late ^=. then b.max_days_late
        when b.max_days_late =. then 0
end as  Ld
from output.sample_y_n_deln a
left join work.sample_y_n_deln b
    on a.contract=b.contract and a.delnum+1=b.delnum

;quit;

所以我想重复这个,但最大 _ld_2、max_ld_3 等

和delnum+2原始delnum或+1 max_ld_1 delnum,所以n+1次我希望它以n=12结束。我是 SAS 的新手,我不确定 do 循环如何适应 sql 步骤,或者我是否需要将此作为数据步骤然后循环它。

https://imgur.com/a/JRMxjFs

我想要的是一个简单的循环,可以对这个逻辑进行 n+1 次迭代。

  proc sql;

    create table MMx
    as select distinct a.*,b.max_days_late as max_LD_2,case 
        when b.max_days_late ^=. then b.max_days_late
       /*       when b.max_days_late =. then 0*/
end as  Ld
from work.MMx a
left join work.MMx b
    on a.contract=b.contract and a.delnum+2=b.delnum

;quit;

     proc sql;

     create table MMx
     as select distinct a.*,b.max_days_late as max_LD_3,case 
        when b.max_days_late ^=. then b.max_days_late
     /*     when b.max_days_late =. then 0*/
     end as  Ld
     from work.MMx a
     left join work.MMx b
    on a.contract=b.contract and a.delnum+3=b.delnum

      ;quit;

     proc sql;
     
     create table MMx
     as select distinct a.*,b.max_days_late as max_LD_4,case 
        when b.max_days_late ^=. then b.max_days_late
     /*     when b.max_days_late =. then 0*/
          end as  Ld
     from work.MMx a
     left join work.MMx b
    on a.contract=b.contract and a.delnum+4=b.delnum

     ;quit;

     proc sql;

     create table MMx
     as select distinct a.*,b.max_days_late as max_LD_5,case 
        when b.max_days_late ^=. then b.max_days_late
     /*     when b.max_days_late =. then 0*/
     end as  Ld
     from work.MMx a
     left join work.MMx b
    on a.contract=b.contract and a.delnum+5=b.delnum

     ;quit;

     proc sql;

     create table MMx
     as select distinct a.*,b.max_days_late as max_LD_6,case 
        when b.max_days_late ^=. then b.max_days_late
     /*     when b.max_days_late =. then 0*/
     end as  Ld
     from work.MMx a
     left join work.MMx b
    on a.contract=b.contract and a.delnum+6=b.delnum

     ;quit;

     proc sql;

     create table MMx
     as select distinct a.*,b.max_days_late as max_LD_7,case 
        when b.max_days_late ^=. then b.max_days_late
     /*     when b.max_days_late =. then 0*/
     end as  Ld
     from work.MMx a
     left join work.MMx b
    on a.contract=b.contract and a.delnum+7=b.delnum

     ;quit;

     proc sql;

     create table MMx
     as select distinct a.*,b.max_days_late as max_LD_8,case 
        when b.max_days_late ^=. then b.max_days_late
     /*     when b.max_days_late =. then 0*/
     end as  Ld
     from work.MMx a
     left join work.MMx b
    on a.contract=b.contract and a.delnum+8=b.delnum

     ;quit;

     proc sql;

     create table MMx
     as select distinct a.*,b.max_days_late as max_LD_9,case 
        when b.max_days_late ^=. then b.max_days_late
     /*     when b.max_days_late =. then 0*/
     end as  Ld
     from work.MMx a
     left join work.MMx b
    on a.contract=b.contract and a.delnum+9=b.delnum

     ;quit;

     proc sql;

     create table MMx
     as select distinct a.*,b.max_days_late as max_LD_10,case 
        when b.max_days_late ^=. then b.max_days_late
     /*     when b.max_days_late =. then 0*/
     end as  Ld
     from work.MMx a
     left join work.MMx b
    on a.contract=b.contract and a.delnum+10=b.delnum

     ;quit;
     proc sql;

     create table MMx
     as select distinct a.*,b.max_days_late as max_LD_11,case 
        when b.max_days_late ^=. then b.max_days_late
     /*     when b.max_days_late =. then 0*/
     end as  Ld
     from work.MMx a
     left join work.MMx b
    on a.contract=b.contract and a.delnum+11=b.delnum

     ;quit;

     proc sql;

     create table MMx
     as select distinct a.*,b.max_days_late as max_LD_12,case 
        when b.max_days_late ^=. then b.max_days_late
     /*     when b.max_days_late =. then 0*/
     end as  Ld
     from work.MMx a
     left join work.MMx b
    on a.contract=b.contract and a.delnum+12=b.delnum

     ;quit;

但有一个列名,如 max_ld_1、max_ld_2 等

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。