我有一个SQL语句,我希望使用SAS EG(9.4)自动化。以下语句已在Teradata SQL Assistant中进行了测试并正常运行。
select * from TD.DATA where date='2015-06-01'
现在我希望通过proc SQL传递来推送它,并将日期提供给SQL程序,就像这样....
proc sql;
connect to teradata as tera(user=&tera_user password="&tera_pwd" tdpid=terap);
create table MYDATA as
select * from connection to tera
(
select * from TD.DATA where date='2015-06-01'
);
disconnect from tera;
quit;
上面的代码已经过测试,并产生与前一个SQL语句完全相同的输出。但是,我真正想要的是做这样的事情:
%let input_date='2015-06-01';
proc sql;
connect to teradata as tera(user=&tera_user password="&tera_pwd" tdpid=terap);
create table MYDATA as
select * from connection to tera
(
select * from TD.DATA where date=&input_date.
);
disconnect from tera;
quit;
我尝试了各种报价和不同日期格式的组合....我在这里缺少什么?感谢。
答案 0 :(得分:6)
您可以使用%BQUOTE()
宏函数来解析单引号内的宏变量。
%let input_date = 2015-06-01; proc sql; connect to teradata as tera(user=&tera_user password="&tera_pwd" tdpid=terap); create table MYDATA as select * from connection to tera ( select * from TD.DATA where date = %BQUOTE('&INPUT_DATE') ); disconnect from tera; quit;
答案 1 :(得分:1)
试试这个:
%let input_date=2015-06-01;
proc sql;
connect to teradata as tera(user=&tera_user password="&tera_pwd" tdpid=terap);
create table MYDATA as
select * from connection to tera
(
select * from TD.DATA where date=%str(%'&input_date%')
);
disconnect from tera;
quit;
答案 2 :(得分:0)
与日期201501的格式相同,以制作有效的宏变量
%let input_date = 201506;
%let input_date2=input(put(intnx('month',%sysfunc(inputn(&input_date,yymmn6.)),0,'b'),10.),yymmddd10.)
proc sql;
connect to teradata as tera(user=&tera_user password="&tera_pwd" tdpid=terap);
create table MYDATA as
select * from connection to tera
(
select * from TD.DATA where date = %BQUOTE('&INPUT_DATE2')
);
disconnect from tera;
quit;