SAS Macros with parameters (parameterized macros)



SAS Macros have been studied within 3 parts here. Please go through all the three parts Sequentially;
Follow the links to study;


  
·              Macros with Parameters
    1. Positional Parameters
    2. Keyword Parameters
    3. Mixed Parameters

In mixed parameters while calling and definition positional parameters must be listed before keyword parameters.

 

·              Difference between positional and keyword parameters;

1.                  In positional parameters there is one to one correspondence between macro definition and macro call. The calling sequence should be same as defined sequence

2.                  In keyword parameters sequence is not important and number of parameters used while calling the macro are also not important

 

·              MACRO WITH POSITIONAL PARAMETERS

 

         /* Macro Defination */

%macro myprnit(var1,var2)

               PROC PRINT data = &var1..&var2;

               Run;

%mend myprint;

 

/* Macro Call */

%myprint (store,daily)

 

·              MACRO WITH KEYWORD PARAMETERS

%macro myprint(var1= work, var2=t)

            PROC PRINT data = &var1..&var2;

            Run;

%mend myprint;

 

/* Macro Call */

%myprint (var2=new_datset)

 

Here while calling the macro; macro variable are optional; because it can assign default values given at the time of definition.

 

·              MACRO WITH MIXED PARAMETER

%macro myprint (var1, var2=t)

            PROC PRINT data = &var1..&var2;

            Run;

%mend myprint;

 

/* Macro Call */

%myprint (store,)

 

Here positional parameters must be declared and called before keyword
 
Comments