改进 %NRQUOTE 'removal'
Improvement on %NRQUOTE 'removal'
我有以下有效的代码,但我想知道是否有人可以提出 'removing' 和 %nrquote
的更好方法。我不得不添加一个 %SUBSTR
函数,该函数有效,但我很想知道是否还有其他建议,以及是否有人可以帮助解释为什么没有 %let
代码无法工作mvar
宏定义中的语句。
/* Automatically generated by DI Studio - cannot change */
%let _where_clause = %nrquote(name = %'Henry%');
%let _mac1 = %nrquote(lemk);
%let _variable = weight;
%let _input0 = sashelp.class;
/* End of auto-generated code */
options mprint;
%macro mvar;
%if &_where_clause ^= %then %do;
/* Re-assign the _where_clause variable to 'remove' %nrquote */
%let _where_clause = %substr(&_where_clause,1);
where &_where_clause
%end;
%mend mvar;
proc sql;
select &_variable into :&_mac1
from &_input0
%mvar
;
quit;
如果没有 %let 语句,代码将失败并出现此错误:
NOTE: Line generated by the macro variable "_WHERE_CLAUSE".
1 name = 'Henry'
-
22
MPRINT(MVAR): where name = '
NOTE: Line generated by the macro variable "_WHERE_CLAUSE".
1 name = 'Henry'
-
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
a numeric constant, a datetime constant, a missing value, (, *, +, -, ALL, ANY,
BTRIM, CALCULATED, CASE, INPUT, PUT, SELECT, SOME, SUBSTRING, TRANSLATE, USER.
ERROR 200-322: The symbol is not recognized and will be ignored.
114 ;
MPRINT(MVAR): Henry'
您需要 %UNQUOTE,这是 %LET 正在发生的事情,它取消引用引号。
Change
where &_where_clause
to
where %unquote(&_where_clause)
我有以下有效的代码,但我想知道是否有人可以提出 'removing' 和 %nrquote
的更好方法。我不得不添加一个 %SUBSTR
函数,该函数有效,但我很想知道是否还有其他建议,以及是否有人可以帮助解释为什么没有 %let
代码无法工作mvar
宏定义中的语句。
/* Automatically generated by DI Studio - cannot change */
%let _where_clause = %nrquote(name = %'Henry%');
%let _mac1 = %nrquote(lemk);
%let _variable = weight;
%let _input0 = sashelp.class;
/* End of auto-generated code */
options mprint;
%macro mvar;
%if &_where_clause ^= %then %do;
/* Re-assign the _where_clause variable to 'remove' %nrquote */
%let _where_clause = %substr(&_where_clause,1);
where &_where_clause
%end;
%mend mvar;
proc sql;
select &_variable into :&_mac1
from &_input0
%mvar
;
quit;
如果没有 %let 语句,代码将失败并出现此错误:
NOTE: Line generated by the macro variable "_WHERE_CLAUSE".
1 name = 'Henry'
-
22
MPRINT(MVAR): where name = '
NOTE: Line generated by the macro variable "_WHERE_CLAUSE".
1 name = 'Henry'
-
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
a numeric constant, a datetime constant, a missing value, (, *, +, -, ALL, ANY,
BTRIM, CALCULATED, CASE, INPUT, PUT, SELECT, SOME, SUBSTRING, TRANSLATE, USER.
ERROR 200-322: The symbol is not recognized and will be ignored.
114 ;
MPRINT(MVAR): Henry'
您需要 %UNQUOTE,这是 %LET 正在发生的事情,它取消引用引号。
Change
where &_where_clause
to
where %unquote(&_where_clause)