- %macro tri_vs_ctrl(total=,ctrl=);
- %local tri;
- %global _rst_;
- %let tri=%cmpres(%sysfunc(compress(&total,%sysfunc(compress(&ctrl)))));
- data _null_;
- array _par_[%sysfunc(countw(&total))]_temporary_;
- length text $1024.;
- do i=%sysfunc(tranwrd(&tri,%str( ),%str(,)));
- do j=%sysfunc(tranwrd(&ctrl,%str( ),%str(,)));
- call missing(of _par_[*]);
- _par_[i]=1;
- _par_[j]=-1;
- text=catx(',',text,quote(cat(i,' vs ',j))||''||catx('',of _par_[*]));
- end;
- end;
- call symputx('_rst_',tranwrd(text,'.','0'));
- run;
- %mend;
调用示例如下:
- %tri_vs_ctrl(total=1 2 3 4,ctrl=1);
- %put &=_rst_;
- _RST_="2 vs 1" -1 1 0 0,"3 vs 1" -1 0 1 0,"4 vs 1" -1 0 0 1
- %tri_vs_ctrl(total=1 2 3 4,ctrl=2);
- %put &=_rst_;
- _RST_="1 vs 2" 1 -1 0 0,"3 vs 2" 0 -1 1 0,"4 vs 2" 0 -1 0 1
- %tri_vs_ctrl(total=1 2 3 4,ctrl=1 2);
- %put &=_rst_;
- _RST_="3 vs 1" -1 0 1 0,"3 vs 2" 0 -1 1 0,"4 vs 1" -1 0 0 1,"4 vs 2" 0 -1 0 1
你或许可以完全改用宏语句实现,就更为方便了。


雷达卡




京公网安备 11010802022788号







