[英]How to use a macro variable in the from table in proc SQL
我需要在下面的SQL直通代碼中使用宏變量,但會不斷收到錯誤,而且我不知道如何解決!
%let mon1 = 201209;
proc sql;
/*Connection String*/
connect to odbc as sqldata (noprompt="uid=dr;pwd=raven;dsn=FinanceDW;") ;
create table output1 as /*This will create a SAS data set*/
select * /*this will select all from the command below and insert into the SAS dataset*/
from connection to sqldata
( /*Insert SQL CODE below - it can only use SQL any SAS code will cause it to fail*/
select top 10 *
from "AUS_&mon1._FCM15.dbo.contract"
);/*End SQL code*/
disconnect from sqldata;/*Close connection*/
quit;
然后,我得到以下錯誤(從日志中提取):
23 select top 10 *
24 from "AUS_&mon1._FCM15.dbo.contract"
25
26 );
ERROR: CLI describe error: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name
'AUS_201209_FCM15.dbo.contract'. : [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s)
could not be prepared.
我需要從中獲取數據的實際表稱為AUS_201209_FCM15,所以我不知道問題是什么?
弄清楚了。 需要使用%bquote
並刪除""
:
%let mon1 = 201209;
proc sql;
connect to odbc as sqldata (noprompt="uid=dr;pwd=raven;dsn=FinanceDW;") ;
create table output1 as
select *
from connection to sqldata
select top 10 *
from %bquote(AUS_&mon1._FCM15.dbo.contract)
);
disconnect from sqldata
quit;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.