<?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: Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/816676#M322372</link>
    <description>&lt;P&gt;Whenever you get an error in the log, you need to show us the &lt;FONT color="#FF0000"&gt;ENTIRE&lt;/FONT&gt; log for that macro (or for the PROC or DATA step that has the error). Do not show us a small portion of the log, as you have done. (And this applies to all of your future questions here in the SAS Communities about errors in the log, SHOW US THE ENTIRE LOG FOR THAT STEP)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For macros which have errors in the log, it is also critical to first turn on the debugging option by running this code, and then running your macro again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then show us the ENTIRE log for the macro.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jun 2022 16:38:26 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-06-06T16:38:26Z</dc:date>
    <item>
      <title>Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/816659#M322365</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro data_m(d);
%do j=1 %to &amp;amp;num_files_&amp;amp;d._rf;
data rf_&amp;amp;d._&amp;amp;j._n;
set  rf_&amp;amp;d._&amp;amp;j. (where = (RecordType = "Parent" ));
number=_N_;
run;

%end;
%mend data_m; 
%data_m(MAT);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;When I run the above code i am getting this error. " A character operand was found in the %EVAL function or %IF condition where a numeric operand&lt;BR /&gt;is required. The condition was: &amp;amp;num_files_&amp;amp;d._rf&lt;BR /&gt;ERROR: The %TO value of the %DO J loop is invalid."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know why the macro does not work when I use "&amp;amp;d." in num_files.Any ideas how to fix it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 15:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/816659#M322365</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2022-06-06T15:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/816663#M322367</link>
      <description>&lt;P&gt;Is there a macro variable that exists which has the value you would like to use as the upper limit for the %DO loop?&amp;nbsp; What is the name of that macro variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it num_files_mat_rf ?&lt;/P&gt;
&lt;P&gt;If so, then try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do j=1 %to &amp;amp;&amp;amp;num_files_&amp;amp;d._rf;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 16:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/816663#M322367</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-06-06T16:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/816675#M322371</link>
      <description>&lt;P&gt;First a generic debugging hint with macros: Options Mprint; set before executing macro code will show more details of generated statements. If your problems revolve around how macro variables are used you may want&amp;nbsp; the SYMBOLGEN option as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second: show an example of the non-macro code that worked.&lt;/P&gt;
&lt;P&gt;Where are the macro variable(s) that start with NUM_FILES assigned?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And lastly test this and show us the result.&lt;/P&gt;
&lt;PRE&gt;%macro dummy(d);
%put num_files raw is &amp;amp;num_files_&amp;amp;d._rf;&lt;BR /&gt;%put num_files indirect is &amp;amp;&amp;amp;num_files_&amp;amp;d._rf;
%mend;

%dummy (MAT);
&lt;/PRE&gt;
&lt;P&gt;I suspect that you are going to need to build an indirect reference as &amp;amp;somevar&amp;amp;d.rtf is not going to resolve to a number that the %do loop is going to expect as MAT is not numeric.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 16:31:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/816675#M322371</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-06T16:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/816676#M322372</link>
      <description>&lt;P&gt;Whenever you get an error in the log, you need to show us the &lt;FONT color="#FF0000"&gt;ENTIRE&lt;/FONT&gt; log for that macro (or for the PROC or DATA step that has the error). Do not show us a small portion of the log, as you have done. (And this applies to all of your future questions here in the SAS Communities about errors in the log, SHOW US THE ENTIRE LOG FOR THAT STEP)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For macros which have errors in the log, it is also critical to first turn on the debugging option by running this code, and then running your macro again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then show us the ENTIRE log for the macro.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 16:38:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/816676#M322372</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-06T16:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/816677#M322373</link>
      <description>&lt;P&gt;Your expression can never yield a number since it ends in the letters _rf, plus the macro variable D has been assigned the string MAT.&lt;/P&gt;
&lt;P&gt;Perhaps you are trying to reference a macro variable named NUM_FILES_MAT_RF ?&lt;/P&gt;
&lt;P&gt;You need to double the first &amp;amp;.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;&amp;amp;num_files_&amp;amp;d._rf&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS will&amp;nbsp;replace the &amp;amp;&amp;amp; with &amp;amp; and remind itself to re-scan the resulting string for more macro variable references. So after the first pass the value has become:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;num_files_MAT_rf
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So if that resolves to a digit string then your %DO loop should run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why not just eliminate the %DO loop&amp;nbsp; altogether?&amp;nbsp; Instead of writing N new datasets just write one new dataset that as the data from ALL of the original dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro data_m(d);
data rf_all_&amp;amp;d. ;
  set  rf_&amp;amp;d._: (where = (RecordType = "Parent" )) indsname=indsname;
  if indsname ne lag(indsname) then number=0;
  number+1;
  dsname=indsname;
run;
%mend data_m; 
%data_m(MAT);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If there are other dataset names that start with the string RF_MAT_ then to only get ones with the numeric sffix in that range use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  set rf_&amp;amp;d._1 - rf_&amp;amp;d._&amp;amp;&amp;amp;num_files_&amp;amp;d._rf ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You might need to add something like macro function like a %UNQUOTE() around that second one to prevent the macro processor and the SAS language process from confusing each other into seeing two separate names there.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  set rf_&amp;amp;d._1 - %unquote(rf_&amp;amp;d._&amp;amp;&amp;amp;num_files_&amp;amp;d._rf) ....&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2022 17:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/816677#M322373</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-06T17:01:20Z</dc:date>
    </item>
  </channel>
</rss>

