BookmarkSubscribeRSS Feed
simple_gearle
Calcite | Level 5

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?

 

Thanks,

Andrea

 

/*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;
%end;
%mend;

 

/*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;
%end;
%end;
%mend;

 

/*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.);

....

2 REPLIES 2
sh0e
Obsidian | Level 7

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 );
simple_gearle
Calcite | Level 5

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...)

...

mend;

 

/*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=;
rc=dosubl(sr);
end;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1276 views
  • 0 likes
  • 2 in conversation