2013-06-05 22 views
2

總之創建一個數據集的變量,我很努力實現以下目標:從宏觀變量同時包含引號,雙引號和不匹配的報價

data _null_; 
input x $ 1-50 ; 
call symput('problem',x); 
cards4; 
'this' "is '' my "string"" from 'hell! 
;;;; 
run; 

data _null_; 
x="%superQ(problem)"; 
put x=; 
run; 

的supe叭功能不管理不匹配報價的一個好工作然而連續引號(「」)仍然解析回單引號的變量X

這是尋址?

當前的結果:

x='this' "is '' my "string" from 'hell! 

期望的結果:

x='this' "is '' my "string"" from 'hell! 

回答

3

簡短的回答是,你可以在這裏使用SYMGET:

data _null_; 
x=symget("problem"); 
put x=; 
run; 

如果不是對某些選項理由,提供關於上下文的更多信息。我還會看看我是否可以在這裏指向Toby(SAS-L宏引用專家)或其他人,以查看他們是否有任何建議來處理沒有SYMGET的情況。

從SAS-L,FriedEgg(太)發表了以下額外的解決方案:

resolve=resolve('%superq(problem)'); 

他還指出,你可以在掩蓋它的方式,如果你有超過對照:

data _null_; 
input x $ 1-50 ; 
call symput('problem',quote(x)); 
cards4; 
'this' "is '' my "string"" from 'hell! 
;;;; 
run; 

data _null_; 
    x=&problem; 
    put x=; 
run;