%macro second(param);
%let a = %eval(¶m); &a
%mend second;
%macro first(exp);
%if (%second(&exp) ge 0) %then
%put **** result >= 0 ****;
%else
%put **** result < 0 ****;
%mend first;
options mlogic;
%first(1+2)MLOGIC(FIRST): Beginning execution. MLOGIC(FIRST): Parameter EXP has value 1+2 MLOGIC(SECOND): Beginning execution. MLOGIC(SECOND): Parameter PARAM has value 1+2 MLOGIC(SECOND): %LET (variable name is A) MLOGIC(SECOND): Ending execution. MLOGIC(FIRST): %IF condition (%second(&exp) ge 0) is TRUE MLOGIC(FIRST): %PUT **** result >= 0 **** MLOGIC(FIRST): Ending execution.
%macro second(param);
%let a = %eval(¶m); &a
%mend second;
%macro first(exp);
data _null_;
var=%second(&exp);
put var=;
run;
%mend first;
options mprint;
%first(1+2)MPRINT(FIRST): DATA _NULL_; MPRINT(FIRST): VAR= MPRINT(SECOND):3 MPRINT(FIRST):; MPRINT(FIRST): PUT VAR=; MPRINT(FIRST): RUN; VAR=3
options mprint mfile;
filename mprint 'external-file';MPRINT(macroname:という接頭語を付けないで外部ファイルに保存されます。
options mprint mfile;
filename mprint 'TEMPOUT';
%macro temp;
data one;
%do i=1 %to 3;
x&i=&i;
%end;
run;
%mend temp;
%tempMPRINT(TEMP): DATA ONE;
NOTE: The macro generated output from MPRINT will also be written
to external file '/u/local/abcdef/TEMPOUT' while OPTIONS
MPRINT and MFILE are set.
MPRINT(TEMP): X1=1;
MPRINT(TEMP): X2=2;
MPRINT(TEMP): X3=3;
MPRINT(TEMP): RUN;DATA ONE; X1=1; X2=2; X3=3; RUN;
options symbolgen; %let a1=dog; %let b2=cat; %let b=1; %let c=2; %let d=a; %let e=b; %put **** &&&d&b ****; %put **** &&&e&c ****;
SYMBOLGEN:&& resolves to &.SYMBOLGEN:Macro variable D resolves to a SYMBOLGEN:Macro variable B resolves to 1 SYMBOLGEN:Macro variable A1 resolves to dog **** dog **** SYMBOLGEN:&& resolves to &.SYMBOLGEN:Macro variable E resolves to b SYMBOLGEN:Macro variable C resolves to 2 SYMBOLGEN:Macro variable B2 resolves to cat **** cat ****
%let nickname = %str(My name%'s O%'Malley, but I%'m called Bruce); %put *** &nickname ***;
SYMBOLGEN: Macro variable NICKNAME resolves to
My name's O'Malley, but I'm called Bruce
SYMBOLGEN: Some characters in the above value which were
subject to macro quoting have been
unquoted for printing.
*** My name's O'Malley, but I'm called Bruce ***|
状況
|
例
|
|---|---|
|
マクロ変数の値を表示する
|
%PUT ****&=variable-name****; |
|
変数の値の先頭または末尾の空白を確認する
|
%PUT ***&variable-name***; |
|
ループの実行中に、二重アンパサンドの置換を確認する
|
%PUT ***variable-name&i = &&variable-name***; |
|
条件の評価を確認する
|
%PUT ***This condition was met.***; |
%macro totinv(var);
%global macvar;
data inv;
retain total 0;
set Sasuser.Houses end=final;
total=total+&var;
if final then call symput("macvar",put(total,dollar14.2));
run;
%if &trace = ON %then
%do;
%put *** Tracing macro scopes. ***;
%put _USER_;
%end;
%mend totinv;
%let trace=ON;
%totinv(price)
%put *** TOTAL=&macvar ***;*** Tracing macro scopes.***Tracing macro scopes. *** TOTINV VAR price GLOBAL TRACE ON GLOBAL MACVAR $1,240,800.00 *** TOTAL= $1,240,800.00 ***