Macro parameters providing defaults

From sasCommunity
Jump to: navigation, search

When I present seminars, I ask at the end of the session: "What did you learn?"

One common idea is that we can provide default values to macro parameters.

These demonstration macros show various ways of doing this.

%macro X1(data=);
%put _local_;
%mend;
%X1()
 
%macro X2(data=sashelp.class);
%put _local_;
%mend;
%X2()
 
%macro X3(data=.);
%if &data eq . %then
    %let data = sashelp.shoes;
 
%if     %symglobl(libname)
    and %symglobl(memname) %then
    %let data = &libname..&memname;
%put _local_;
%mend;
%X3()
%let libname = library;
%let memname = demo_data;
%X3()
 
%macro X4(data=.);
%let data=%sysfunc(ifc(&data eq .
                   and %symglobl(libname)
                   and %symglobl(memname)
                  ,%nrstr(&libname..&memname)
                  ,sashelp.bweight));
%put _local_;
%mend;
%symdel libname memname;
%X4()
%let libname = library;
%let memname = demo_data;
%X4()

--Ronald_J._Fehd macro.maven == the radical programmer 7 Aug 2017