在int Comp列中查找连续零的最大日期

发布于 2025-02-11 01:30:01 字数 1091 浏览 1 评论 0原文

我想计算PRIN Comp列中连续零的最大日期。在结束日期列中,日期应为连续零的最大日期。我尝试使用等级功能,但无法获得最大日期

AGREEMENTID DUEDATE                 PRINCOMP    INTCOMP END_DATE
267        15FEB2017:00:00:00.000   0           46411   
267        15MAR2017:00:00:00.000   32258       64167   
267        15APR2017:00:00:00.000   32554       63871   
267        15MAY2017:00:00:00.000   32852       63573   
267        16AUG2019:00:00:00.000   34521       61904   
267        16SEP2019:00:00:00.000   0           56912   
267        15OCT2019:00:00:00.000   0           51612   
267        15NOV2019:00:00:00.000   0           53333   
267        16DEC2019:00:00:00.000   0           51612   
267        15JAN2020:00:00:00.000   0           53333   
267        15FEB2020:00:00:00.000   0           53333   15FEB2020:00:00:00.000
267        15AUG2029:00:00:00.000   82334       3491    
267        15SEP2029:00:00:00.000   83109       2716    
267        15OCT2029:00:00:00.000   83892       1933    
267        15NOV2029:00:00:00.000   84682       1143    
267        15DEC2029:00:00:00.000   36691       346 

I want to calculate max date of consecutive zero in PRIN COMP column. In end date column the date should be max date of consecutive zero. I tried using rank function but not able to get that max date

AGREEMENTID DUEDATE                 PRINCOMP    INTCOMP END_DATE
267        15FEB2017:00:00:00.000   0           46411   
267        15MAR2017:00:00:00.000   32258       64167   
267        15APR2017:00:00:00.000   32554       63871   
267        15MAY2017:00:00:00.000   32852       63573   
267        16AUG2019:00:00:00.000   34521       61904   
267        16SEP2019:00:00:00.000   0           56912   
267        15OCT2019:00:00:00.000   0           51612   
267        15NOV2019:00:00:00.000   0           53333   
267        16DEC2019:00:00:00.000   0           51612   
267        15JAN2020:00:00:00.000   0           53333   
267        15FEB2020:00:00:00.000   0           53333   15FEB2020:00:00:00.000
267        15AUG2029:00:00:00.000   82334       3491    
267        15SEP2029:00:00:00.000   83109       2716    
267        15OCT2029:00:00:00.000   83892       1933    
267        15NOV2029:00:00:00.000   84682       1143    
267        15DEC2029:00:00:00.000   36691       346 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅沫记忆 2025-02-18 01:30:01
data have;
   infile cards firstobs=2;
   input id date:datetime. princomp intcomp;
   format date datetime.;
   cards;
AGREEMENTID DUEDATE                 PRINCOMP    INTCOMP END_DATE
267        15FEB2017:00:00:00.000   0           46411   
267        15MAR2017:00:00:00.000   32258       64167   
267        15APR2017:00:00:00.000   32554       63871   
267        15MAY2017:00:00:00.000   32852       63573   
267        16AUG2019:00:00:00.000   34521       61904   
267        16SEP2019:00:00:00.000   0           56912   
267        15OCT2019:00:00:00.000   0           51612   
267        15NOV2019:00:00:00.000   0           53333   
267        16DEC2019:00:00:00.000   0           51612   
267        15JAN2020:00:00:00.000   0           53333   
267        15FEB2020:00:00:00.000   0           53333   15FEB2020:00:00:00.000
267        15AUG2029:00:00:00.000   82334       3491    
267        15SEP2029:00:00:00.000   83109       2716    
267        15OCT2029:00:00:00.000   83892       1933    
267        15NOV2029:00:00:00.000   84682       1143    
267        15DEC2029:00:00:00.000   36691       346 
;;;;
proc print;
   run;
data want;
   set have;
   by id princomp notsorted;
   if princomp eq 0 then do;
      if first.princomp then c=0;
      c+1;
      if c gt 2 then do;
         if last.princomp and not first.princomp then edate = date;
         end;
      end;
   format edate datetime.;
   run;
proc print;
   run;
data have;
   infile cards firstobs=2;
   input id date:datetime. princomp intcomp;
   format date datetime.;
   cards;
AGREEMENTID DUEDATE                 PRINCOMP    INTCOMP END_DATE
267        15FEB2017:00:00:00.000   0           46411   
267        15MAR2017:00:00:00.000   32258       64167   
267        15APR2017:00:00:00.000   32554       63871   
267        15MAY2017:00:00:00.000   32852       63573   
267        16AUG2019:00:00:00.000   34521       61904   
267        16SEP2019:00:00:00.000   0           56912   
267        15OCT2019:00:00:00.000   0           51612   
267        15NOV2019:00:00:00.000   0           53333   
267        16DEC2019:00:00:00.000   0           51612   
267        15JAN2020:00:00:00.000   0           53333   
267        15FEB2020:00:00:00.000   0           53333   15FEB2020:00:00:00.000
267        15AUG2029:00:00:00.000   82334       3491    
267        15SEP2029:00:00:00.000   83109       2716    
267        15OCT2029:00:00:00.000   83892       1933    
267        15NOV2029:00:00:00.000   84682       1143    
267        15DEC2029:00:00:00.000   36691       346 
;;;;
proc print;
   run;
data want;
   set have;
   by id princomp notsorted;
   if princomp eq 0 then do;
      if first.princomp then c=0;
      c+1;
      if c gt 2 then do;
         if last.princomp and not first.princomp then edate = date;
         end;
      end;
   format edate datetime.;
   run;
proc print;
   run;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文