将带引号的SAS宏变量分配给数据步骤变量

将带引号的SAS宏变量分配给数据步骤变量,sas,Sas,如何使下面的陈述有效 %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 faile

如何使下面的陈述有效

%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;
它返回时出错 错误386-185:应为算术表达式

错误200-322:符号无法识别,将被忽略


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

您需要使用宏引用函数来解决此问题

/* 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;
日志

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
您可以使用SYMGET()函数检索宏变量的值,而不必担心任何宏引用(至少在进行检索的步骤中)

如果确实需要引用宏变量的值并使用它生成带引号的字符串,那么请使用QUOTE()函数确保所有嵌入的引号正确地加倍,以便生成的字符串是有效的字符串文字

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

谢谢你,维尚。它可以工作,但在我的实际情况中,宏变量是自动生成的,但不是直接赋值的。汤姆以前的解决方案可以帮我解决这个问题。:)@Greatvia-如果您能在问题中提及与您的要求相同的内容,就像您在问题中要求解决错误一样,那就太好了。今后请记住这一点。
data _null_;
   put %sysfunc(quote(&qcomment));
run;