代码之家  ›  专栏  ›  技术社区  ›  IndigoChild

在sas中创建两个日期之间的日期序列

  •  0
  • IndigoChild  · 技术社区  · 6 年前

    所以我有一个代码如下:

    %let mon_first=02Jan2018;
    %let mon_last=02Mar2018;
    %let start=%sysfunc(inputn(mon_first, Date9.), yymmn6.);
    %let end=%sysfunc(inputn(mon_first, Date9.), yymmn6.);
    
    %macro call(yrmon, yr, mon);
    

    名为 %call 因此,我使用了以下循环:

    %do i = &start. to &end.;
    yrmon=put(i)
    yr=substr(yrmon, 1,4);
    mon=substr(yrmon,5,2);
    %call(yrmon, yr, mon);
    %end;
    

    我在 yrmon=put(i) 声明: Statement is not valid or it is used out of proper order.

    0 回复  |  直到 6 年前
        1
  •  3
  •   Tom    6 年前

    使用整数作为循环计数器。然后将整数与 intnx() 来计算下个月。

    %let mon_first=02Jan2018;
    %let mon_last=02Mar2018;
    %do i=0 %to %sysfunc(intck(month,"&mon_first"d,"&mon_last"d));
      %let month=%sysfunc(intnx(month,"&mon_first"d,&i));
      %let yrmon=%sysfunc(putn(&month,yymmn6));
      %let yr=%sysfunc(year(&month),4);
      %let mon=%sysfunc(month(&month),z2);
    
    ...
    
    %end;