具有逗号的SAS宏变量要转换为带逗号的单引号
SAS Macro Variable having commas to be converted to single quotes with commas
有人可以帮助我如何使用单引号更新宏变量。
我从数据集中获取数字作为逗号分隔值,如下所示:
2108008080、2108008081、2108888082、2108858090、213856345 等
我必须在 SQL 中传递每条记录,其中条件为 Phone_numbers in (¤t_macro_variable)。为此,我必须在每个值周围添加单引号,因为 Phone_numbers 列是 Oracle DB 的字符字段。
非常感谢任何帮助。我无法从 SAS 社区获得太多帮助。
quote 函数应该可以解决问题。
您必须遍历 stringLine 中的所有单词并添加引号。
%let macroVar = %str(2108008080, 2108008081, 2108888082, 2108858090, 213856345);
data _null_;
n = count("¯oVar",",");
length
quotedword 00.;
quotedword = "";
do i = 1 to n+1;
word = scan("¯oVar",i,",");
y = quote(compress(word));
quotedword = strip(quotedword) || "," || strip(y);
end;
quotedword = substr(quotedword,2); /* removing first comma from beginning */
call symputx("macroVarUpdated",quotedword);
run;
%put ¯oVar;
%put ¯oVarUpdated;
使用 PROC SQL
和 select ... into
语法:
/* Build list of quoted phone numbers separated by a comma */
proc sql ;
select cats("'",phone_number,"'") into :PHONELIST separated by ','
from phonedata ;
quit ;
/* Then pass it into your Oracle query... */
proc sql ;
select vars
from ora.table
where phone in(&PHONELIST) ;
quit ;
你试过CATQ()
功能了吗?使用 1
修饰符生成单引号。使用 a
修饰符来引用所有术语。使用 c
修饰符生成逗号作为输出分隔符。
%let x=2108008080, 2108008081, 2108888082, 2108858090, 213856345;
%put %sysfunc(catq(1ac,&x));
产生:
'2108008080','2108008081','2108888082','2108858090','213856345'
有人可以帮助我如何使用单引号更新宏变量。
我从数据集中获取数字作为逗号分隔值,如下所示:
2108008080、2108008081、2108888082、2108858090、213856345 等 我必须在 SQL 中传递每条记录,其中条件为 Phone_numbers in (¤t_macro_variable)。为此,我必须在每个值周围添加单引号,因为 Phone_numbers 列是 Oracle DB 的字符字段。
非常感谢任何帮助。我无法从 SAS 社区获得太多帮助。
quote 函数应该可以解决问题。 您必须遍历 stringLine 中的所有单词并添加引号。
%let macroVar = %str(2108008080, 2108008081, 2108888082, 2108858090, 213856345);
data _null_;
n = count("¯oVar",",");
length
quotedword 00.;
quotedword = "";
do i = 1 to n+1;
word = scan("¯oVar",i,",");
y = quote(compress(word));
quotedword = strip(quotedword) || "," || strip(y);
end;
quotedword = substr(quotedword,2); /* removing first comma from beginning */
call symputx("macroVarUpdated",quotedword);
run;
%put ¯oVar;
%put ¯oVarUpdated;
使用 PROC SQL
和 select ... into
语法:
/* Build list of quoted phone numbers separated by a comma */ proc sql ; select cats("'",phone_number,"'") into :PHONELIST separated by ',' from phonedata ; quit ; /* Then pass it into your Oracle query... */ proc sql ; select vars from ora.table where phone in(&PHONELIST) ; quit ;
你试过CATQ()
功能了吗?使用 1
修饰符生成单引号。使用 a
修饰符来引用所有术语。使用 c
修饰符生成逗号作为输出分隔符。
%let x=2108008080, 2108008081, 2108888082, 2108858090, 213856345;
%put %sysfunc(catq(1ac,&x));
产生:
'2108008080','2108008081','2108888082','2108858090','213856345'