<?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 Concatenating Macro Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-Macro-Variables/m-p/414010#M279982</link>
    <description>&lt;P&gt;Hello All, I have a macro I have written to execute a Proc SQL statement on a number of variables. I am fairly new to the macro facility and is likely the cause of the issue I am seeing. In this example there a 9 data sets in the library. There are also variables created from a different macro called ds1, ds2, ds3, ds4, ds5, ds6, ds7, ds8 and ds9 which contain the actual data set name. The macro was written as I the number of data sets in the library can change from one run to the next with completely different data sets. However, as it is currently written, I get the following 2 SAS errors for each of the 9 data sets:&lt;/P&gt;&lt;P&gt;ERROR 22-322: Expecting a name.&lt;/P&gt;&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know there are other ways in which to get record counts, but note this is just an example to ensure I can process the data sets as the true resulting operations will be a bit more complex (No need to suggest easier methods to get record counts). Any assistance on how I can reference the macro variable associated with the string 'ds'&amp;nbsp;and the iteration variable i&amp;nbsp;to reference the resolved macro variable names ds1 if on iteration 1, ds2 if on iteration 2, etc. I have bolded the lines of code to which my question pertains to. Oh we are on version&amp;nbsp;7.100.2.3 if that makes a difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The macro code is written as:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro GetRecordCounts(lib, worklib=work);&lt;BR /&gt;
data &amp;amp;worklib..DataSetNames;
set &amp;amp;worklib..DataSetNames end=end;
rownum=_n_;
call symputx('ds'||trim(put(rownum,5. -L)),trim(memname));
run;&lt;BR /&gt;
proc sql;
select max(rownum) Into :dscount From &amp;amp;worklib..DataSetNames;
quit;&lt;BR /&gt;
&lt;STRONG&gt;%do i = 1 %to &amp;amp;dscount&lt;/STRONG&gt;;&lt;BR /&gt;
proc sql;
&lt;STRONG&gt;Select '&amp;amp;&amp;amp;dsn' as DataSetName, Count(*) As RecordSetCount From &amp;amp;lib..&amp;amp;'ds'||&amp;amp;i.;&lt;/STRONG&gt;
Quit;&lt;BR /&gt;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 16 Nov 2017 14:33:28 GMT</pubDate>
    <dc:creator>Jmitch</dc:creator>
    <dc:date>2017-11-16T14:33:28Z</dc:date>
    <item>
      <title>Concatenating Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-Macro-Variables/m-p/414010#M279982</link>
      <description>&lt;P&gt;Hello All, I have a macro I have written to execute a Proc SQL statement on a number of variables. I am fairly new to the macro facility and is likely the cause of the issue I am seeing. In this example there a 9 data sets in the library. There are also variables created from a different macro called ds1, ds2, ds3, ds4, ds5, ds6, ds7, ds8 and ds9 which contain the actual data set name. The macro was written as I the number of data sets in the library can change from one run to the next with completely different data sets. However, as it is currently written, I get the following 2 SAS errors for each of the 9 data sets:&lt;/P&gt;&lt;P&gt;ERROR 22-322: Expecting a name.&lt;/P&gt;&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know there are other ways in which to get record counts, but note this is just an example to ensure I can process the data sets as the true resulting operations will be a bit more complex (No need to suggest easier methods to get record counts). Any assistance on how I can reference the macro variable associated with the string 'ds'&amp;nbsp;and the iteration variable i&amp;nbsp;to reference the resolved macro variable names ds1 if on iteration 1, ds2 if on iteration 2, etc. I have bolded the lines of code to which my question pertains to. Oh we are on version&amp;nbsp;7.100.2.3 if that makes a difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The macro code is written as:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro GetRecordCounts(lib, worklib=work);&lt;BR /&gt;
data &amp;amp;worklib..DataSetNames;
set &amp;amp;worklib..DataSetNames end=end;
rownum=_n_;
call symputx('ds'||trim(put(rownum,5. -L)),trim(memname));
run;&lt;BR /&gt;
proc sql;
select max(rownum) Into :dscount From &amp;amp;worklib..DataSetNames;
quit;&lt;BR /&gt;
&lt;STRONG&gt;%do i = 1 %to &amp;amp;dscount&lt;/STRONG&gt;;&lt;BR /&gt;
proc sql;
&lt;STRONG&gt;Select '&amp;amp;&amp;amp;dsn' as DataSetName, Count(*) As RecordSetCount From &amp;amp;lib..&amp;amp;'ds'||&amp;amp;i.;&lt;/STRONG&gt;
Quit;&lt;BR /&gt;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Nov 2017 14:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-Macro-Variables/m-p/414010#M279982</guid>
      <dc:creator>Jmitch</dc:creator>
      <dc:date>2017-11-16T14:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-Macro-Variables/m-p/414011#M279983</link>
      <description>The bolding did not work, but it is the 4th line from the bottom.</description>
      <pubDate>Thu, 16 Nov 2017 14:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-Macro-Variables/m-p/414011#M279983</guid>
      <dc:creator>Jmitch</dc:creator>
      <dc:date>2017-11-16T14:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-Macro-Variables/m-p/414015#M279984</link>
      <description>&lt;P&gt;First of all, single quotes will prevent the resolution of macro variables.&lt;/P&gt;
&lt;P&gt;Second, if you need to indirectly resolve macro variables, do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var2=XX;

%let i=2;
%let result=&amp;amp;&amp;amp;var&amp;amp;i;

%put result=&amp;amp;result;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I also guess that using '&amp;amp;&amp;amp;dsn' is a mistake?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 14:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-Macro-Variables/m-p/414015#M279984</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-16T14:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-Macro-Variables/m-p/414031#M279985</link>
      <description>&lt;P&gt;Thanks Kurt! That was exactly what I needed. Much appreciated. Also, thanks for pointing out the &amp;amp;&amp;amp;dsn. After adding double quotes and using dsn as the variable name for indirect resolution of the macro variables, it now prints the data set name as intended. Kind regards!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 15:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-Macro-Variables/m-p/414031#M279985</guid>
      <dc:creator>Jmitch</dc:creator>
      <dc:date>2017-11-16T15:08:32Z</dc:date>
    </item>
  </channel>
</rss>

