Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在proc SQL的from表中使用宏变量_Sql_Variables_Macros - Fatal编程技术网

如何在proc SQL的from表中使用宏变量

如何在proc SQL的from表中使用宏变量,sql,variables,macros,Sql,Variables,Macros,我需要在下面的SQL pass-through代码中使用一个宏变量,但不断出现错误,我不知道如何修复它 %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 * /*

我需要在下面的SQL pass-through代码中使用一个宏变量,但不断出现错误,我不知道如何修复它

%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;