proc sql;
create table vv as select a.date,count(*) as date_in_cnt
from v (keep=date) as a
left join v as b
on b.date>=a.date>=b.date_be
group by a.date
order by a.date;
quit;[/code:2095l6xj]作者: shiyiming 时间: 2011-4-9 00:46 标题: Re: 请问如何计数? 看了vicky女士的一系列回答得出一点结论是:
知性,优雅,和善于理解。作者: shiyiming 时间: 2011-4-10 01:31 标题: Re: 请问如何计数? 高实在高作者: Qiong 时间: 2011-4-11 13:26 标题: Re: 请问如何计数? [quote:htkhwpn9]
由 jingju11 » 2011年 4月 9日 周六 12:46 am
Shy~~忒荣幸了~~作者: shiyiming 时间: 2011-4-15 06:33 标题: Re: 请问如何计数? I did not know anyone check the result or not.
I run the solution code above, and found some problems, e.g. obveriously, only 1 record within 20050203--20050104, but the result is 2.
my solution is:
[code:l94vzml6]data a;
input date1 yymmdd8. date2 yymmdd10.;
format date1 date2 date9.;
unid=catx('_',date1,date2);
cards;
20050203 2005-1-4
20050303 2005-2-1
20050325 2005-2-23
20050412 2005-3-13
20050418 2005-3-19
20050427 2005-3-28
20050509 2005-4-9
20050510 2005-4-10
20050518 2005-4-18
20050523 2005-4-23
20050526 2005-4-26
20050531 2005-5-1
20050603 2005-5-4
20050606 2005-5-7
20050607 2005-5-8
20060619 2006-5-20
20060623 2006-5-24
20060627 2006-5-28
20060627 2006-5-28
;
run;
proc sql;
create table b as
select distinct unid,count(distinct date1) as cnt
from (select d1.unid,d2.date1
from a d1,a d2
where d1.date2<=d2.date1<=d1.date1)
group by unid
order by unid;
quit;[/code:l94vzml6]