我想用帶空格的雙引號(即「」)替換宏變量中傳遞的變量之間的空格。請在下面找到我使用的代碼和我得到的結果。使用帶空格的引號替換宏變量值中的空格
%let str7=ABC DEF UVW XYZ;
%let str8 = %qsysfunc(quote(%qsysfunc(tranwrd(%qsysfunc(compbl(%qsysfunc(strip(%upcase(&str7.))))),%str(),%nrstr(%")))));
%put ^^^^&str8;
的日誌顯示:
18 %put ^^^^&str8;
^^^^"ABC""DEF""UVW""XYZ"
我需要這是 「ABC」, 「DEF」 「UVW」 「XYZ」。
我也曾嘗試以下...
proc fcmp outlib=work.funcs.funcs;
function delimit_words(iString $) $;
result = '"' || tranwrd(cats(compbl(iString))," ", '" ,"') || '"';
return (result);
endsub;
run;
%let x = A B C ;
%let y = %sysfunc(delimit_words(&x));
%put &y;
,但它給了我下面的錯誤...
錯誤:在%SYSFUNC或%QSYSFUNC宏函數引用的DELIMIT_WORDS功能不找到。
我已經使用了Jeff給出的以下方法。
data test;
id =1; _var="ABC"; output;
id =1; _var="DEF"; output;
id =1; _var="UVW"; output;
id =2; _var="UVW"; output;
id =3; _var="ABC"; output;
id =3; _var="UVW"; output;
id =3; _var="XYZ"; output;
id =4; _var="ABC"; output;
id =4; _var="XYZ"; output;
run;
%macro __test1(_byvar=, _qnam=, _id=);
proc sort data= test out=_test;
by &_byvar.;
%if %superq(_qnam) ne %then
%do;
%let __tmpmv_qnam = %qsysfunc(prxchange(%bquote(s/\b/"/),-1,%bquote(&_qnam)));
*";
%put ^^^^^&__tmpmv_qnam.;
where upcase(&_id) in (&__tmpmv_qnam);
%end;
run;
%mend;
%__test1 (_byvar=id ,_qnam = ABC UVW, _id=_var);
日誌diaplayed以下錯誤:
SYMBOLGEN: Macro variable _QNAM resolves to ABC UVW
ERROR: Literal contains unmatched quote.
請在這一個幫助。
感謝您使用更整潔的方法,但它給了我以下錯誤。錯誤:文字包含無與倫比的報價。 – 2014-10-30 14:38:00
我有一個錯字,現在修正了(buote而不是quote)。對於那個很抱歉。 – Jeff 2014-10-30 14:39:26
是的。我明白了,但錯誤依然存在。 – 2014-10-30 14:46:41