【发布时间】:2019-02-27 07:12:51
【问题描述】:
我有 10 个 csv 文件想要执行 PROC IMPORT,每次一个,具体取决于用户输入的值。例如,用户将输入 201801 以运行 2018 年 1 月的 csv 文件(PROC IMPORT)。
对于这种情况,我尝试使用子字符串 &period(它存储用户输入的 yymmn6. 值),然后从那里放入 proc 导入。我的代码如下:
%let period=201812;
%macro convertdate();
data convertdate;
year=substr("&period",1,4);
month=substr("&period",5,2);
if month='01' then newmonth='jan';
if month='02' then newmonth='feb';
if month='03' then newmonth='mac';
if month='04' then newmonth='apr';
if month='05' then newmonth='may';
if month='06' then newmonth='jun';
if month='07' then newmonth='jul';
if month='08' then newmonth='aug';
if month='09' then newmonth='sep';
if month='10' then newmonth='oct';
if month='11' then newmonth='nov';
if month='12' then newmonth='dec';
run;
/*Assign convertdate the only distinct record into macro, then set as the data step for proc import*/
%if month='01' %then %do;
%let newmonth=jan;
%end;
/*proc import and remaining transformation from existing script*/
proc import out=rmr_raw_source
file="/sasdata/source/user_files/re_&newmonth.2018.xlsx"
dbms=xlsx replace;
sheet="re_&newmonth.2018";
getnames=no;
dbsaslabel=none;
run;
%mend;
%convertdate;
但是,它不起作用。我收到以下警告:
警告:明显的符号引用 NEWMONTH 未解析。
谁有更好的解决方案?
【问题讨论】:
-
月份变量存在于数据集中。您需要创建全局变量。您可以尝试调用 symput:if month='01' then call symput('newmonth','jan'); 更多文档:support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/…
标签: sas