我想用带空格的双引号(即“”)替换宏变量中传递的变量之间的空格。请在下面找到我使用的代码和我得到的结果。使用带空格的引号替换宏变量值中的空格
%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