Want to create some dataset based on a varibale in SAS

时间:2017-03-14 10:22:00

标签: sas

I am very new to SAS. I have written code to do some data manipulation in SAS. The challenge is that every time before executing this piece of code, I must manually change the name of datasets. Which took lot of time. There is some pattern in naming convention. Suppose my dataset name is XXX_IN_MUM_Dec_2016. So, before executing I have change the name to XXX_IN_MUM_Jan_2017

Sample Code:

data XXX_IN_MUM_Dec_2016;
set XXX_IN_MUM_Dec_2016;
FILENAME_MONTH=input(CATS(strip("01"),SCAN(strip(filename_BILL),4,"_")),anydtdte.);
format FILENAME_MONTH monyy7.;
if intnx('month','1SEP2016'd,0,'b'). <= FILENAME_MONTH <= intnx('month','1FEB2017'd,0,'e') then output;
run;

In above code, I want to pass a variable instead of dataset name (XXX_IN_MUM_Jan_2017).

Thanks Mohd Shams

1 个答案:

答案 0 :(得分:0)

每次启动SAS会话系统时,都会自动创建宏变量SYSDATE。它显示两位数的日期,月份名称的前三个字母和两位数的年份。所以你可以使用它:

%let month = %substr(&sysdate, 3, 3);
%let year = %substr(&sysdate, 6, 2);
%put &month &year;

data XXX_IN_MUM_&month._20&year;
    set XXX_IN_MUM_&month._20&year;
    /* your code*/
run;

今天,数据集名称已解析为XXX_IN_MUM_mar_2017。