参考whymath的code,稍微修改了点code如下,
%macro tri_vs_ctrl(total=,ctrl=);
%local tri;
%global _rst_;
%let tri=&total.;
%let _rst_=;
%do i=1 %to %sysfunc(countw(&ctrl));
%let num_i = %scan(&ctrl, &i);
%let tri=%cmpres(%sysfunc(compress(&tri,%sysfunc(compress(&num_i)))));
%do j=1 %to %sysfunc(countw( &tri ));
%let num_j = %scan(&tri, &j);
data _NULL_;
length text $1024.;
text=catx('!', "&_rst_.", catx('-', &num_i, &num_j));
call symputx('_rst_',text);
run;
%end;
%end;
%put &=_rst_;
%mend;
结果
%tri_vs_ctrl(total=1 2 3 4,ctrl=1);
output: _RST_=1-2!1-3!1-4
%tri_vs_ctrl(total=1 2 3 4,ctrl=2);
output:_RST_=2-1!2-3!2-4
%tri_vs_ctrl(total=1 2 3 4,ctrl=1 2);
ouptut:_RST_=1-2!1-3!1-4!2-3!2-4