- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 294 个
- 通用积分
- 2.0010
- 学术水平
- 13 点
- 热心指数
- 16 点
- 信用等级
- 13 点
- 经验
- 2473 点
- 帖子
- 112
- 精华
- 0
- 在线时间
- 330 小时
- 注册时间
- 2015-12-18
- 最后登录
- 2020-8-29
|
- data company1;
- input id $ country $ startyear;
- label id="企业ID"
- country="出口国家ID"
- startyear="开始出口年份";
- datalines;
- 1391910 392 2009
- 1392010 410 2008
- 1392061 392 2007
- 1392061 842 2009
- 1392321 842 2009
- 1392390 842 2009
- 1852990 158 2008
- 1852990 344 2009
- 1900120 344 2008
- 1900120 392 2009
- 1900120 410 2008
- ;
- data company2;
- input id $ country $ startyear;
- label id="企业ID"
- country="出口国家ID"
- startyear="开始出口年份";
- datalines;
- 1391910 392 2009
- 1391910 410 2008
- 1391910 842 2007
- 1392010 410 2008
- 1392010 392 2007
- 1392010 410 2009
- 1392061 392 2007
- 1392061 842 2009
- 1392321 842 2009
- 1392390 842 2009
- 1852990 158 2008
- 1852990 344 2009
- 1900120 344 2008
- 1900120 392 2009
- 1900120 410 2008
- 1900120 528 2004
- 1900120 458 2001
- 1900120 484 2003
- ;
- /*company1和company2中有id代表企业,country为出口的国家,startyear
- 为开始对该国出口的时间,想在a的基础上得到在a出口某个country之前,在b中
- 该企业有无出口其他国家的经历,并统计出出口国家的个数。
- 例如企业1391910,在a中,2009年开始向392出口,
- 再看b中2009年前该企业是否有出口其他国家的经历,
- 在b中,该企业2007年和2008年分别开始出口842和410国家,
- 则有出口经验,且有两个国家。依次类推。。。*/
- /*程序1*/
- /*增加标识变量*/
- data company1;set company1;group="A表";run;
- data company2;set company2;group="B表";run;
- /*安装id与开始出口年份降序排序*/
- proc sort data=company1 out=company1_1;by id startyear;run;
- /*取来自A表开始出口的最小年份*/
- data nodup_min_year;set company1_1;by id;if first.id;run;
- /*join内联查询按id并且按另一个变量条件筛选*/
- proc sql;
- create table test1 as
- select B.id,B.country,B.startyear,B.group,A.startyear
- from nodup_min_year as A /*原来A表去重并保留最小的出口年份*/
- join company2 As B /*原来表B*/
- On A.id=B.id /*关联企业id相同的记录*/
- and B.startyear < A.startyear;
- /*按A、B表在相同的企业id下,筛选B表年份小于A表最小年份的出口国家*/
- quit;/*test1表输出了来自B表满足年份条件的企业及出口国家数*/
- proc sql;/*计算每个企业每年出口国家数*/
- create table test2 as select *,count(country)
- as num_country from test1
- group by id,startyear;
- quit;
- title color=red bold font="Time New Roman" "企业每年出口国家情况报告" ;
- ods pdf file="D:\country_report.pdf";
- ods layout gridded rows=2 row_gutter=0in;
- proc report data=test2
- style(header)={background=white foreground=blue}
- style(column)={background=white foreground=black};
- column id startyear country num_country;
- define id / group;
- define startyear / "出口年份" group;
- define country / group;
- define num_country / "出口国家数量" analysis sum;
- break after id / ol skip summarize suppress;
- rbreak after / dol skip summarize;
- run;
- ods layout end;
- ods pdf close;
复制代码
|
|