2015-11-02 125 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