This one is clear in logic.
data have;
input id date: yymmdd10.;
format date yymmdd10.;
cards;
1 2012-02-16
1 2012-02-17
1 2012-02-20
1 2012-03-01
1 2012-03-03
2 2012-02-20
2 2012-02-23
2 2012-02-24
2 2012-03-03
3 2012-03-01
3 2012-03-02
;
run;
proc means data=have nway noprint;
class id ;
var date ;
output out=minmax(keep=id min_dat ...
I try to use fake data which is the same as your data and apply the program to get the result you need.
data have;
input id date: yymmdd10.;
format date yymmdd10.;
cards;
1 2012-02-16
1 2012-02-17
1 2012-02-20
1 2012-03-01
1 2012-03-03
2 2012-02-20
2 2012-02-23
2 2012-02-24
2 2012-03-03
3 2012-03-01
3 2012-03-02
;
run;
data want(rename=(_date=date));
set have;
by id;
retain _date count_day;
format _date yymmdd10.;
if first.id then do;
count_day=1;
_date=date;
output;
end;
else do;
_date=intnx('day',_date,1);
if _date<date then do until (_date=date);
count_day=count_day;
output;
_date=intnx('day',_date,1);
end;
if _date=date then do;
count_day+1;
output;
end;
end;
drop date;
run;
proc print;
run;
In LZ' excel files, It seems that series date without stop is needed to be produced, meanwhile a statistical variable for total days is also needed to be calculated.
加一个用do loop 的方法。
The first row of the original excel file need to be changed
for sucessfull import.
假如你已经把excel数据import到 dataset: data0320.
变量名为 ID, DATE,DAYS,NUM
Try the following code.
proc sort data=data0320;
by ID date;
run;
data test_A;
format date date_tmp yymmdd10.;
retain date_tmp;
set data0330;
by id;
if first.id then do;
date_tmp = date;
output;
end;
interval = intck('day', date_tmp, date);
if interval = 1 then do;
date_tmp = date;
output;
end;
if interval > 1 then do;
do i = 1 to interval;
date_tmp = intnx('day', date_tmp, 1);
output;
end;
end;
drop interval i days;
run;
data test_result (rename=(date_tmp=date));
set test_a (drop=date);
by id;
if first.id then days=1;
else days+1;
run;