2015-11-02 124 views
1

如何使以下语句有效?用引号将SAS宏变量赋值给数据步骤var

%let qccomment= /n ORACLE execute error: ORA-20001: User xyxlll 
     does not have acccess to the gva BA_DEV ORA-06512: at 
     "M_UTIL", line 51 ORA-06512: at line 1. /nTable XY_XY does not exist 
     (Oracle extract data failed); 

%put &qccomment; 
data null; 
    i ="&qccomment"; 
    put i; 
run; 

它错误返回 ERROR 386-185:期待的算术表达式。

错误200-322:该符号不被识别,将被忽略。

错误76-322:语法错误,语句将被忽略。

回答

2

可以使用SYMGET()函数来检索值的宏变量,而不必担心任何宏观引用(至少在进行检索的步骤中)。

data _null_; 
    i = symget('qcomment'); 
    put i= ; 
run; 

如果你真的需要引用宏变量的值,并用它来生成一个带引号的字符串然后使用引号()函数,以确保所有嵌入式引号正确一倍,这样生成的字符串是有效的字符串字面量。

data _null_; 
    put %sysfunc(quote(&qcomment)); 
run; 
+0

谢谢,汤姆。两种方式都很好。 – Greatvia

0

您需要使用宏引用函数来解决这个问题,

/* Using %BQUOTE in let statement to quote the string */ 
%let qccomment= %bquote(/n ORACLE execute error: ORA-20001: User xyxlll 
    does not have acccess to the gva BA_DEV ORA-06512: at 
    "M_UTIL", line 51 ORA-06512: at line 1. /nTable XY_XY does not exist 
    (Oracle extract data failed)); 

%put &qccomment; 
data null; 
    i ="&qccomment"; 
    put i; 
run; 

LOG

11 %let qccomment= %bquote(/n ORACLE execute error: ORA-20001: User xyxlll 
12   does not have acccess to the gva BA_DEV ORA-06512: at 
13   "M_UTIL", line 51 ORA-06512: at line 1. /nTable XY_XY does not  exist 
14   (Oracle extract data failed)); 
15 
16 %put &qccomment; 
/n ORACLE execute error: ORA-20001: User xyxlll   does not have  acccess to the gva BA_DEV 
ORA-06512: at   "M_UTIL", line 51 ORA-06512: at line 1. /nTable XY_XY  does not exist 
    (Oracle extract data failed) 
17 data null; 
18  i ="&qccomment"; 
19  put i; 
20 run; 

/n ORACLE execute error: ORA-20001: User xyxlll   does not have acccess to the gva BA_DEV 
ORA-06512: at   "M_UTIL", line 51 ORA-06512: at line 1. /nTable XY_XY does not exist 
    (Oracle extract data failed) 
NOTE: The data set WORK.NULL has 1 observations and 1 variables. 
NOTE: DATA statement used (Total process time): 
     real time   0.08 seconds 
     cpu time   0.00 seconds 
+0

谢谢Vishant。它可以工作,但在我的真实情况下,宏变量是自动生成的,但没有直接分配。以前的汤姆的解决方案可以帮助我。 :) – Greatvia

+0

@ Greatvia-如果你可以在你的问题中提及与你的要求相同的东西,那就太好了,因为你的问题是你要求解决你的错误。请继续记住这一点。 – Vishant