increment date based on a refence date

时间:2017-08-04 13:09:20

标签: sas

Hi I have a data with dates which has to be incremented to a value stored in another variable.

Sno     Date1     Date2
1     20120201  20130101
1     20120201  20130101
2     20030812  20030908
2     20030812  20030908
3     20110402  20110602
3     20110402  20110602

No I have to increment date1 longitudinally till (date2 - 20days). How can I use this in loop

if I use like

do i=a to b-20; 
increment=intnx('day',date1,i);
end; 

then it takes the SAS number of days and goes beyond the date2

1 个答案:

答案 0 :(得分:0)

data table;
infile datalines dlm='|';
input sno date1 :anydtdte. date2 :anydtdte.;
format date1 date2 date.;
datalines;
1|20120201|20130101
1|20120201|20130101
2|20030812|20030908
2|20030812|20030908
3|20110402|20110602
3|20110402|20110602
;
run;

data result;
set table;
do increment=date1 to date2-20;
  output;
end;
format increment date.;
run;

假设date1date2存储为字符