楼主: yaniwei1314
3705 11

SAS怎么将一个宏变量分成指定变量个数的N个小宏变量啊? [推广有奖]

11
jingju11 发表于 2015-11-3 11:11:21
JingJu11: My classmate provided the following code
  1. %macro test(var, n);
  2.         %local k c i j;
  3.         %let k=0;
  4.         %let c=%sysfunc(countw(&var%str( )));
  5.         %do i =1 %to &n;
  6.                 %let var&i=;
  7.                 %do j=1 %to %sysevalf((&c-&k)/(&n+1-&i), c);
  8.                         %let k =%eval(&k +1);
  9.                         %let var&i =&&var&i %scan(&var, &k);
  10.                         %end;        %put var&i:&&var&i;
  11.                 %end;
  12. %mend test;
  13. %test(1 2 3,3)
复制代码

12
jingju11 发表于 2015-11-4 07:58:26
jingju11 发表于 2015-11-3 11:11
JingJu11: My classmate provided the following code
Some people raised a question to my friend: Any pros and cons on programming on pure macro syntax vs. using some other interfaces, such as data step or procedures? The answer is: if you can program on pure macro syntax, you should do it. Because you can place the code anywhere you want; on the other hand, doing macro programming on data step or procedures can only work wherever it is suitable. It usually works as an independent function-like unit. The bad thing for macro syntax programming is that always is hindered and complicated by macro variable masking scheme.
JingJu

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-29 11:30