簡単な質問は、既存のデータからマクロを繰り返し呼び出す方法だと思います。多くの場合、そうではありません。多くの場合、通常の SAS コードでは何でも単純に実行します。しかし、あなたは私たちに何の情報も提供してくれなかったので、マクロを繰り返し呼び出す正当な理由があるのかもしれません (通常は避けようとしますが、私は確かにそうすることがあります)。
上記の DavB の回答をこの回答に組み込みます。両方の値をパラメーターとして持たず、最初のパラメーターのみを使用してから、マクロ内でそれを 2 番目のパラメーターに変換します。
データ ドリブン マクロ呼び出しを作成するには、約 10 通りの方法があります。ここに3つあります。
%macro foo(param=);
%let second_param=%sysfunc(translate(¶m,"___","-.a"));
%put ¶m &second_param;
%mend foo;
*Method 1: Call Execute. This puts code in a queue to execute after the data step completes.
This has some advantages, namely that you can build code easily and can modify it with data step functions,
and some disadvantages, namely that some timing issues (when things happen internal to SAS) exist
and can be difficult to remember/work around. Not used all that often as a result of those timing issues
but for simple things can be useful.;
data _null_;
set sashelp.class;
mcall = cats('%foo(param=',name,')');
call execute(mcall);
run;
*Method 2: PROC SQL select into. This creates a list and stores it in a macro variable.
Quick and easy (much shorter code-wise) compared to the other solutions, but has one significant limitation:
a hard limit to how many total characters can be stored in a macro variable (I forget exactly how much, but around 20,000).
So if you are calling the macro a thousand or more times this might fail - it writes a warning to the log if so.
Use NOPRINT with PROC SQL unless you want to see what is generated.;
proc sql;
select cats('%foo(param=',name,')') into :mcalllist separated by ' ' from sashelp.class;
quit;
&mcalllist;
*Method 3: Include file generation. This creates an actual text file with your code in it, then you include that code.
In some ways the most transparent - you can easily debug the code - but also a lot of lines of code to write comparatively.
Does not have the length limitation of the PROC SQL method, although it does have the normal limitations of included code.
The temp file is written to your WORK directory, so you can navigate to that to see the contents, and/or use a non-TEMP file
and write it out to a directory of your choosing in order to see it.
;
filename foo temp;
data _null_;
file foo;
set sashelp.class;
mcall = cats('%foo(param=',name,')');
put mcall $;
run;
%include foo;