derby-10.x.x.x.jar
答案 0 :(得分:2)
在SAS中操作这样的日期并不是一种非常有用的方法,但如果您只是这样做以学习SAS,那么可以将它们放在带有二维数组的do循环中:
%let yyyymm =201506;
data parm;
format yyyymm1-yyyymm11 yymm1-yymm11 $6.
yyyy0 $4.;
array D(3,11) yyyymm1-yyyymm11
yymm1-yymm11
yyyy1-yyyy11 ;
yyyymm0 ="&yyyymm";
yymm0 = substr(yyyymm0, 3, 4);
yyyy0 = substr(yyyymm0, 1, 4);
mm0 = substr(yyyymm0, 5, 2);
*Loop through to process your variables for each month ;
do i=1 to 11 ;
D(1,i) = put(intnx('month', input(yyyymm0, yymmn6.), - i, 'beginning'), yymmn6.);
D(2,i) = substr( D(1,i),3,4);
D(3,i) = substr( D(2,i) ,1,4);
end ;
run;
答案 1 :(得分:0)
因此,如果想要使用这些日期来生成数据集(或文件)名称,那么为什么不在数据步骤中生成名称?
%let yyyymm =201506;
%let prefix=data_ ;
data parms;
length start month date 8 dsname $32 ;
format start date yymmdd10.;
start = input("&yyyymm.01",yymmdd8.);
do month=0 to 12 ;
date = intnx('month',start,month,'b');
dsname = "&prefix" || substr(put(date,yymmddn8.),1,6);
output;
end;
run;
proc print;运行;
Obs start month date dsname
1 2015-06-01 0 2015-06-01 data_201506
2 2015-06-01 1 2015-07-01 data_201507
3 2015-06-01 2 2015-08-01 data_201508
4 2015-06-01 3 2015-09-01 data_201509
5 2015-06-01 4 2015-10-01 data_201510
6 2015-06-01 5 2015-11-01 data_201511
7 2015-06-01 6 2015-12-01 data_201512
8 2015-06-01 7 2016-01-01 data_201601
9 2015-06-01 8 2016-02-01 data_201602
10 2015-06-01 9 2016-03-01 data_201603
11 2015-06-01 10 2016-04-01 data_201604
12 2015-06-01 11 2016-05-01 data_201605
13 2015-06-01 12 2016-06-01 data_201606