我希望有人可以帮我回答这个问题:我有两个程序,一个是proc sql,一个是数据步骤。 proc sql工作,数据步骤没有。我不明白为什么?
%let _run_date = '30-jun-2017';
proc sql;
connect to oracle (path='EDRPRD' authdomain='EDRProduction'
buffsize=32767);
create table customer_sets as
select * from connection to oracle (
select *
from customer_set
where start_date <= &_run_date.
and nvl(end_date, &_run_date.) >= &_run_date.
and substr(sets_num,1,2) = 'R9');
quit;
这很好用。但是,这不是:
libname ora oracle path='EDRPRD' authdomain='EDRProduction' schema='CST';
data customer_sets;
set ora.customer_set;
where start_date le &_run_date. and
coalesce(end_date, &_run_date.) ge &_run_date. and
substr(sets_num,1,2) = "R9";
run;
谁能告诉我为什么?
谢谢!
答案 0 :(得分:0)
这会有助于查看错误日志,但是,对于初学者来说,您的日期宏变量,因为它在数据步骤中使用,将被SAS解释为字符串文字,而不是日期。在SAS中,日期文字用引号括起来(单引号或双引号),然后是d
。
您可以按如下方式修改数据步骤,看看是否更好:
%let _run_date = '30-jun-2017';
data customer_sets;
set ora.customer_set;
where start_date le &_run_date.d and
coalesce(end_date, &_run_date.d) ge &_run_date.d and
substr(sets_num,1,2) = "R9";
run;
如果不是问题,请发布包含错误的日志。
修改强>
以上代码包含预先创建的小测试数据:
libname ora (work);
data ora.customer_set;
infile datalines dlm='09'x;
input ID start_date :anydtdte. end_date :anydtdte. sets_num $;
format start_date end_date date.;
datalines;
1 30-may-2017 . R9xxx
2 30-may-2017 31-may-2017 R9xxx
;
run;
%let _run_date = '30-jun-2017';
data customer_sets;
set ora.customer_set;
where start_date le &_run_date.d and
coalesce(end_date, &_run_date.d) ge &_run_date.d and
substr(sets_num,1,2) = "R9";
run;
你可以复制粘贴并按原样运行它,你会发现它工作正常。