我如何使用 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 (将#修改为@)