Professional Documents
Culture Documents
%let city=New Orleans; title "Data for &city"; title "Data for New Orleans";
Macro structure
%MACRO macro-name;
macro definition %MEND macro-name;
%macro dsn; Newdata %mend dsn;
Macro structure
%macro-name title "Display of Data Set %dsn"; title "Display of Data Set Newdata";
Parameter variables
%macro plot(yvar= ,xvar= ); proc plot; plot &yvar*&xvar; run; %mend plot; %plot(yvar=income,xvar=age) %plot(yvar=income,xvar=yrs_educ)
Parameter
Macro execution produces the following code: proc plot; plot income*age; run;
proc plot; plot income*yrs_educ; run;
Delimiters
DATA &NAME1 &NAME2; SET INSALESTEMP; RUN; data &name.1 &name.2 DATA SALES1 SALES2; set in&name..temp; SET INSALES.TEMP;
%put ,symbolgen
%let a=first; %let b=macro variable; %put &a ***&b***; write
Symbolgen
options symbolgen; %let title "%upcase(&proc) of %upcase(&dset)"; SYMBOLGEN: Macro variable PROC resolves to gplot SYMBOLGEN: Macro variable DATA resolves to sasuser.houses
Indirect reference
Series of varable city1 to city20 %let city1=new york ; %put &city&n; Resolve to ???
Indirect reference
1.
2. 3.
resolves && to & passes CITY as text resolves &N into 6 %let var=city; %let n=6; %put &&&var&n;
Global
%let county=Clark; %macro concat; data _null_; length longname $20; longname="&county"||" County"; put longname; run; %mend concat; %concat
scope
%macro holinfo(day,date); %let holiday=Christmas; %put *** Inside macro: ***; %put *** &holiday occurs on &day, &date, 1997. ***; %mend holinfo; %holinfo(Thursday,12/25) %put *** Outside macro: ***; %put *** &holiday occurs on &day, &date, 1997.
%put
_ALL_ _AUTOMATIC_ _GLOBAL_ _LOCAL_ _USER_ %put _ALL_ ;
Scope
DOGS TYPE work GLOBAL ORIGIN North America
Forcing
%macro namelst(name,number); %do n=1 %to &number; &name&n %end; %mend namelst; %let n=North State Industries; proc print; var %namelst(dept,5); title "Quarterly Report for &n"; run;
Forcing
title "Quarterly Report for 6"; %macro namels2(name,number); %local n; %do n=1 %to &number; &name&n %end; %mend namels2;
%eval %sysevalf
%let a =(1+2); %let b =(10*3); %put The value of a is &a; %put The value of b is &b; Resolves to ????
%Eval
%let a=%eval(1+2); %let b=%eval(10*3); The value of a is 3 The value of b is 30 %let d=%eval(10.0+20.0);
%let d=%sysevalf(10.0+20.0);
Call symput
data senior; set census;
if age > 65 then do; %let sr_cit = yes; /* ERROR */
Symput
Call symput
%let sr_age = 0; data senior; set census; if age > 65 then do; call symput("sr_age",age); stop; end; run;
Call symput
data _null_; put "This data set contains data about a person"; put "who is &sr_age years old."; run;
Into clause
proc sql noprint; select style, sqfeet into :type1 - :type4 notrim, :size1 - :size4 from sasuser.houses; %macro putit; %do i=1 %to 4;
%put Row&i: Type=**&&type&i** Size=**&&size&i**; %end; %mend putit; %putit
Macro Quoting
%let printit=proc print; run; ; &put &printit ?????
Quoting
%let p=%str(proc print; run;); &put &p ;
%Nrstr %macro example; %local myvar; %let myvar=abc; %put %nrstr(The string &myvar appears in log output,); %put instead of the variable value.; %mend example;
Mprint
MPRINT(FIRST): DATA _NULL_; MPRINT(FIRST): VAR= MPRINT(SECOND): 3 MPRINT(FIRST): ; MPRINT(FIRST): PUT VAR=; MPRINT(FIRST): RUN; VAR=3
Mlogic
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.
Mprint
%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)
Thank You
Please dont ask any question