a和b的区别没有说,我理解是这样的,对于a中的一条记录,比如 企业=1, 国家=2, startyear=2011, 在b中找到所有企业=1, startyear<2011的记录, 然后统计这里面所有的国家数. 程序如下:
- proc sql;
- create table temp1 as select a.*, b.country from a left join b
- on a.id=b.id and a.startyear>b.startyear;
- create table temp2 as select id, count(distinct country) from temp1 group by id;
- quit;
复制代码
id是企业号