<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using macro variable as positional parameter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-as-positional-parameter/m-p/281246#M56992</link>
    <description>&lt;P&gt;Dear Andrea,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try passing just the _name_ of the macro symbol into the macro. &amp;nbsp;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let Alist = ...;&lt;BR /&gt;&lt;BR /&gt;%macro report( par1, par2, mvarname );

%let localAlist = &amp;amp;&amp;amp;mvarname;&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;%mend report;&lt;BR /&gt;&lt;BR /&gt;%report( value1, value2, Alist );&lt;/PRE&gt;</description>
    <pubDate>Wed, 29 Jun 2016 19:39:33 GMT</pubDate>
    <dc:creator>sh0e</dc:creator>
    <dc:date>2016-06-29T19:39:33Z</dc:date>
    <item>
      <title>Using macro variable as positional parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-as-positional-parameter/m-p/281235#M56986</link>
      <description>&lt;P&gt;I would like to use a list generated by macros to pupulate the positional parameters of a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, I have a large dataset with variables created by 5 arrays along with many other variables. &amp;nbsp;I am using dosubl to iterate through each row of this dataset and create an ODS PDF report for each row. &amp;nbsp;The report is generated using a macro. &amp;nbsp;I would like to this report macro to contain&amp;nbsp;positional parameters that are the variable names of my&amp;nbsp;data table including those generated by the 5 arrays.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To build the list of variables names, I created a macro for one dimensional arrays and one for two dimensional arrays. &amp;nbsp;Then, I am creating a long list of all of the variable names. &amp;nbsp;I want this list of variable names in my macro along with a couple of others parameters. &amp;nbsp;I can't seem to just use &amp;amp;AList..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I build this macro uisng &amp;amp;AList.? &amp;nbsp;Or, is there better way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Andrea&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*macro to build list of variables for one dimensional arrays */&lt;BR /&gt;%macro AvarList1 (prefix, n);&lt;BR /&gt;%local i;&lt;BR /&gt;%do i = 1 %to &amp;amp;n;&lt;BR /&gt;%if &amp;amp;i&amp;lt;&amp;amp;n %then &amp;amp;prefix&amp;amp;i,;&lt;BR /&gt;%else &amp;amp;prefix&amp;amp;i;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*macro to build list of variables for multi dimensional arrays*/&lt;BR /&gt;%macro AvarList2 (prefix1, n1, prefix2, n2);&lt;BR /&gt;%local i; %local j;&lt;BR /&gt;%do i = 1 %to &amp;amp;n1;&lt;BR /&gt;%do j = 1 %to &amp;amp;n2;&lt;BR /&gt;%if &amp;amp;i&amp;lt;&amp;amp;n1 or &amp;amp;j&amp;lt;&amp;amp;n2 %then &amp;amp;prefix1&amp;amp;i&amp;amp;prefix2&amp;amp;j,;&lt;BR /&gt;%else &amp;amp;prefix1&amp;amp;i&amp;amp;prefix2&amp;amp;j;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*List of Array1-Array5 Variable Names*/&lt;BR /&gt;%Let AList = %AvarList1 (Cat,20), %AvarList1 (KNC,20), %AvarList2 (C,20,K,20),%AvarList2 (C,20,S,20),%AvarList2 (C,20,M,20);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*create report macro*/&lt;/P&gt;&lt;P&gt;%macro report (Par1, Par2, &amp;amp;AList.);&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 19:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-as-positional-parameter/m-p/281235#M56986</guid>
      <dc:creator>simple_gearle</dc:creator>
      <dc:date>2016-06-29T19:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro variable as positional parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-as-positional-parameter/m-p/281246#M56992</link>
      <description>&lt;P&gt;Dear Andrea,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try passing just the _name_ of the macro symbol into the macro. &amp;nbsp;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let Alist = ...;&lt;BR /&gt;&lt;BR /&gt;%macro report( par1, par2, mvarname );

%let localAlist = &amp;amp;&amp;amp;mvarname;&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;%mend report;&lt;BR /&gt;&lt;BR /&gt;%report( value1, value2, Alist );&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jun 2016 19:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-as-positional-parameter/m-p/281246#M56992</guid>
      <dc:creator>sh0e</dc:creator>
      <dc:date>2016-06-29T19:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro variable as positional parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-as-positional-parameter/m-p/281255#M56995</link>
      <description>&lt;P&gt;Yes, I see what you mean but let me clarify one thing. &amp;nbsp;Alist is the name of the variables and the report macro will be invoked using the values of the variables. &amp;nbsp;The values will change with each row of the dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alos, if I replace Var1, Var2, Var3... with mvarname I will pass too many parameters to the macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In other words.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Let Alist = Var1, Var2, Var3,....;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro report (Par1, Par2, Var1, Var2, Var3...)&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*these statements get built dynamically using a data step (see below)*/&lt;/P&gt;&lt;P&gt;%report (Par1Value1, Par2Value1, Var1Value1, Var2Value1, Var3Value1,...);&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%report (Par1Value2, Par2Value2, Var1Value2, Var2Value2, Var3Value2,...);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;/*the data set that dynamically builds the report macro statement*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data _null_; set dataset;&lt;BR /&gt;&amp;amp;Array1.; &amp;amp;Array2.; &amp;amp;Array3.; &amp;amp;Array4.; &amp;amp;Array5.;&lt;BR /&gt;by SortedVariable;&lt;BR /&gt;if first.SortedVariable then do;&lt;BR /&gt;sr= cat('%report(', Par1, ',',Par2, ',',catx(',',&amp;amp;alist.),')');&lt;BR /&gt;put sr=;&lt;BR /&gt;rc=dosubl(sr);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 20:12:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-as-positional-parameter/m-p/281255#M56995</guid>
      <dc:creator>simple_gearle</dc:creator>
      <dc:date>2016-06-29T20:12:22Z</dc:date>
    </item>
  </channel>
</rss>

