/*自动获得系统日期数据*/
data _null_;
format month month_last $2.
year year_last $4.;
year=year(today());
year_last=year-1;
month=month(today())-1;
select(month);
when(0) do;
month=12;
month_last=month-1;
end;
when(1) month_last=12;
otherwise month_last=month-1;
end;
if month<10 then month='0' || left(month);
if month_last<10 then month_last='0' || left(month_last);
/*生成导出文件路径及文件名*/
file_source='C:\Documents and Settings\0113920\My Documents\工作\综合工作\数据手册\';
file_tail=year || month || '.xls';
run;
/*生成1-当月、去年1-当月的数据集*/
data r_work.st_a;
do j=1 to month*1;
if j<10 then month_temp='0' || j;
else month_temp=j;
set 'R_fkdata.St'&year.&month_temp.&'i' (keep=Sta_id Traf_mode Trad_mode4 Tode_t Gross_wt Usd I_e_flag)
'R_fkdata.St'&year.&month_temp.&'e' (keep=Sta_id Traf_mode Trad_mode4 Tode_t Gross_wt Usd I_e_flag);
end;
run;
![](https://bbs-cdn.datacourse.cn/static/2017/f68.png)