-1

我正在寻找一个变量观察的日期,并基本上通过其指定的重新定价参数将其向前滚动,直到目标日期

正在使用的数据集是:

data have;
input repricing_frequency date_of_last_repricing end_date;
datalines;

3 15399 21367
10 12265 21367
15 13879 21367
;

format date_of_last_repricing end_date date9.;
informat date_of_last_repricing end_date date9.;
run;

所以我的想法是,我将继续将 3 个月、10 个月或 15 个月的重新定价频率应用于 date_of_last_repricing,直到它尽可能接近日期“2017 年 12 月 31 日”。提前致谢。

编辑包括我最近的工作:

data want;
set have;

repricing_N = intck('Month',date_of_last_repricing,'31DEC2017'd,'continuous');

dateoflastrepricing = intnx('Month',date_of_last_repricing,repricing_N,'E');

format dateoflastrepricing date9.;
informat dateoflastrepricing date9.;
run;
4

1 回答 1

1

INTNX函数将计算一个递增的日期值,并允许指定生成的间隔对齐(在您的情况下是 n 个月的“结束”)

data have;

  format   date_of_last_repricing end_date date9.;
  informat date_of_last_repricing end_date date9.;

  * use 12. to read the raw date values in the datalines;
  input repricing_frequency date_of_last_repricing: 12.  end_date: 12.;
datalines;
3 15399 21367
10 12265 21367
15 13879 21367
;
run;

data want;
  set have;

  status = 'Original';
  output;

  * increment and iterate;
  date_of_last_repricing = intnx('month',
      date_of_last_repricing, repricing_frequency, 'end'
  );
  do while (date_of_last_repricing <= end_date);
    status = 'Computed';
    output;
    date_of_last_repricing = intnx('month',
        date_of_last_repricing, repricing_frequency, 'end'
    );
  end;
run;

如果您只想计算最近的结束日期,例如通过重新定价频率进行迭代时,您不必进行迭代。您可以将月份除以频率,以获得可能发生的迭代次数。

data want2;
  set have;

  nearest_end_month = intnx('month', end_date, 0, 'end');
  if nearest_end_month > end_date then nearest_end_month = intnx('month', nearest_end_month, -1, 'end');

  months_apart = intck('month', date_of_last_repricing, nearest_end_month);
  iterations_apart = floor(months_apart / repricing_frequency);

  iteration_months =  iterations_apart * repricing_frequency;

  nearest_end_date = intnx('month', date_of_last_repricing, iteration_months, 'end');

  format nearest: date9.;
run;

proc sql;
  select id, max(date_of_last_repricing) as nearest_end_date format=date9. from want group by id;
  select id, nearest_end_date from want2;
quit;
于 2018-09-12T16:19:40.767 回答