DATA Step, Macro, Functions and more

Using macro variable as positional parameter

Occasional Contributor
Posts: 6

Using macro variable as positional parameter

I would like to use a list generated by macros to pupulate the positional parameters of a macro.


Basically, I have a large dataset with variables created by 5 arrays along with many other variables.  I am using dosubl to iterate through each row of this dataset and create an ODS PDF report for each row.  The report is generated using a macro.  I would like to this report macro to contain positional parameters that are the variable names of my data table including those generated by the 5 arrays.


To build the list of variables names, I created a macro for one dimensional arrays and one for two dimensional arrays.  Then, I am creating a long list of all of the variable names.  I want this list of variable names in my macro along with a couple of others parameters.  I can't seem to just use &AList..


How can I build this macro uisng &AList.?  Or, is there better way?





/*macro to build list of variables for one dimensional arrays */
%macro AvarList1 (prefix, n);
%local i;
%do i = 1 %to &n;
%if &i<&n %then &prefix&i,;
%else &prefix&i;


/*macro to build list of variables for multi dimensional arrays*/
%macro AvarList2 (prefix1, n1, prefix2, n2);
%local i; %local j;
%do i = 1 %to &n1;
%do j = 1 %to &n2;
%if &i<&n1 or &j<&n2 %then &prefix1&i&prefix2&j,;
%else &prefix1&i&prefix2&j;


/*List of Array1-Array5 Variable Names*/
%Let AList = %AvarList1 (Cat,20), %AvarList1 (KNC,20), %AvarList2 (C,20,K,20),%AvarList2 (C,20,S,20),%AvarList2 (C,20,M,20);


/*create report macro*/

%macro report (Par1, Par2, &AList.);


Posts: 25

Re: Using macro variable as positional parameter

Dear Andrea,


Try passing just the _name_ of the macro symbol into the macro.  For example:


%let Alist = ...;

%macro report( par1, par2, mvarname ); %let localAlist = &&mvarname;


%mend report;

%report( value1, value2, Alist );
Occasional Contributor
Posts: 6

Re: Using macro variable as positional parameter

Yes, I see what you mean but let me clarify one thing.  Alist is the name of the variables and the report macro will be invoked using the values of the variables.  The values will change with each row of the dataset.


Alos, if I replace Var1, Var2, Var3... with mvarname I will pass too many parameters to the macro.


In other words.


%Let Alist = Var1, Var2, Var3,....;


%macro report (Par1, Par2, Var1, Var2, Var3...)




/*these statements get built dynamically using a data step (see below)*/

%report (Par1Value1, Par2Value1, Var1Value1, Var2Value1, Var3Value1,...);

%report (Par1Value2, Par2Value2, Var1Value2, Var2Value2, Var3Value2,...);


/*the data set that dynamically builds the report macro statement*/

data _null_; set dataset;
&Array1.; &Array2.; &Array3.; &Array4.; &Array5.;
by SortedVariable;
if first.SortedVariable then do;
sr= cat('%report(', Par1, ',',Par2, ',',catx(',',&alist.),')');
put sr=;

Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation