2016-08-09 11 views
0

私は次のコードを使用していますが、誰かが%nrquoteの「削除」のより良い方法を考え出すことができるかどうかを知りたいと思います。私は%SUBSTR関数を追加しなければなりませんでしたが、他の提案があるかどうかを知りたいと思っています。mvarマクロ定義内の%letステートメントがないとコードが機能しない理由を説明できます。コードは、このエラーで失敗%のlet文、なし%NRQUOTEの削除の改善

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

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' 
+1

DIスタジオのバグのようです。単一引用符を追加する場合は、結果の値マクロを引用符で囲んではいけません。 – Tom

答えて

2

あなたはそれが引用された引用符をアン引用している、%のLETで何が起こっているかである%のUNQUOTEが必要です。

Change 
where &_where_clause 
to 
where %unquote(&_where_clause) 
関連する問題