Loops 我如何使用Do循环(或其他方法)来自动执行此操作?SAS
所以我想重复这个,但是对于max,ld,2,max,ld,3等等 delnum+2是原始的delnum,或者+1是max_ld_1 delnum,所以n+1次,我希望它以n=12结束。我是SAS的新手,我不确定do循环如何适应sql步骤,或者我是否需要将其作为数据步骤,然后进行循环 我想要的是一个简单的循环,可以对这个逻辑进行n+1次迭代Loops 我如何使用Do循环(或其他方法)来自动执行此操作?SAS,loops,sas,do-loops,Loops,Sas,Do Loops,所以我想重复这个,但是对于max,ld,2,max,ld,3等等 delnum+2是原始的delnum,或者+1是max_ld_1 delnum,所以n+1次,我希望它以n=12结束。我是SAS的新手,我不确定do循环如何适应sql步骤,或者我是否需要将其作为数据步骤,然后进行循环 我想要的是一个简单的循环,可以对这个逻辑进行n+1次迭代 proc sql; create table MMx as select distinct a.*, b.max_days_late as max_LD
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;
但是列名称为max\u ld\u 1、max\u ld\u 2等。请解释您正在尝试做什么。MAX_LD_1、MAX_LD_2等的含义是什么?您的输入数据集是什么样子的?你想创建什么输出?展示你在第二次迭代中是如何创建的。12对我来说是12个月。您是否可能正在进行12个月的滚动计算?您可能希望“垂直”执行计算,然后转置或制表报告,或者使用一个数组(可能包含以模数计算的索引)。通过显示示例数据和预期输出,使问题变得更好。@Tom@Richard。Max_Ld_1、Max_Ld_2是下个月第n个月的整数值。我想将它们添加为每个合同的行,因此每个合同日期的行中有12个时间段。@Richard我尝试了转置,但随后的合并很棘手,因为您无法仅对合同名称进行合并。而一个接一个地转换数据更令人厌烦。
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;