<?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 was resolved but is invalid to use in the loop stop parameter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-was-resolved-but-is-invalid-to-use-in-the-loop-stop/m-p/908996#M358623</link>
    <description>I guess you do not have a %GLOBAL statement for TOT_C, before calling macro PREP_OS_STG. The macro variable now is local to that macro, and unknown in the next macro.&lt;BR /&gt;Either add a %GLOBAL statement, or use CALL SYMPUTX ("tot_c" , _N_ , 'G' ) to put the macro variable in the Global table.</description>
    <pubDate>Wed, 20 Dec 2023 10:50:47 GMT</pubDate>
    <dc:creator>FrankPoppe</dc:creator>
    <dc:date>2023-12-20T10:50:47Z</dc:date>
    <item>
      <title>Macro was resolved but is invalid to use in the loop stop parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-was-resolved-but-is-invalid-to-use-in-the-loop-stop/m-p/908992#M358622</link>
      <description>&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Hello.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;I used this macro many times in several programs and always works fine. Actually, this code already ran with no issues just a few days ago. However, I got this error and I don't know how to fix it. The macro tot_c is resolved correctly with value 34. Then I want to use this value in the loop where (%do j=1 %to &amp;amp;tot_c.) and sas returns the error bellow and stops.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;MPRINT(PREP_OS_STG): data _null_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;MPRINT(PREP_OS_STG): set DIM_CLUS_PSE;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;MPRINT(PREP_OS_STG): call symputx("cluspselist"||trim(left(_n_)),CLUST_PSE_ATRIB);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;MPRINT(PREP_OS_STG): call symput ("tot_c",_n_);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;MPRINT(PREP_OS_STG): run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;257:73 257:118&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;NOTE: There were 34 observations read from the data set WORK.DIM_CLUS_PSE.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;NOTE: DATA statement used (Total process time):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;real time 0.00 seconds&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;cpu time 0.01 seconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;MLOGIC(PREP_OS_STG): %PUT &amp;amp;tot_c.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;SYMBOLGEN: Macro variable TOT_C resolves to 34&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;34&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;MLOGIC(PREP_OS_STG): Ending execution.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;MPRINT(CALC_DIST_KM_STG1): ;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;MLOGIC(CALC_DIST_KM_STG1): %LOCAL J N NEXT_CLUS_PSE&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;WARNING: Apparent symbolic reference TOT_C not resolved.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;&amp;amp;tot_c. &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;ERROR: The %TO value of the %DO J loop is invalid.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="1 2 3 4 5 6 7"&gt;ERROR: The macro CALC_DIST_KM_STG1 will stop &lt;/FONT&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;executing.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;MLOGIC(CALC_DIST_KM_STG1): Ending execution.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 10:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-was-resolved-but-is-invalid-to-use-in-the-loop-stop/m-p/908992#M358622</guid>
      <dc:creator>SCS_78</dc:creator>
      <dc:date>2023-12-20T10:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro was resolved but is invalid to use in the loop stop parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-was-resolved-but-is-invalid-to-use-in-the-loop-stop/m-p/908996#M358623</link>
      <description>I guess you do not have a %GLOBAL statement for TOT_C, before calling macro PREP_OS_STG. The macro variable now is local to that macro, and unknown in the next macro.&lt;BR /&gt;Either add a %GLOBAL statement, or use CALL SYMPUTX ("tot_c" , _N_ , 'G' ) to put the macro variable in the Global table.</description>
      <pubDate>Wed, 20 Dec 2023 10:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-was-resolved-but-is-invalid-to-use-in-the-loop-stop/m-p/908996#M358623</guid>
      <dc:creator>FrankPoppe</dc:creator>
      <dc:date>2023-12-20T10:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro was resolved but is invalid to use in the loop stop parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-was-resolved-but-is-invalid-to-use-in-the-loop-stop/m-p/909001#M358624</link>
      <description>&lt;P&gt;It would help if you also showed us the code. And sorry to be picky, but it would also help if you used a larger font, the size of your text is difficult to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WARNING: Apparent symbolic reference TOT_C not resolved.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In macro PREP_OS_STG, you create the macro variable TOT_C and it has a value of 34. But, the default way SAS macros work, macro variable TOT_C is still undefined outside of the macro PREP_OS_STG, and so it does not have a value when the next macro CALC_DIST_KM_STG1 begins. I realize this does not explain how the code could have run in the past, but that's what I see, and as I said, showing us the code would help.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 11:19:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-was-resolved-but-is-invalid-to-use-in-the-loop-stop/m-p/909001#M358624</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-12-20T11:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro was resolved but is invalid to use in the loop stop parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-was-resolved-but-is-invalid-to-use-in-the-loop-stop/m-p/909022#M358633</link>
      <description>&lt;P&gt;It is obvious how if COULD have worked in the past if you consider the complete rules for&amp;nbsp;scoping of macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you assign a value to a macro variable SAS will first use the macro variable of that name that it currently can see.&amp;nbsp; If no such macro variable exists it will make a new one in the current macro symbol table. Normally inside a macro that symbol table will be LOCAL to the macro currently running and so the macro variable created there will not exist after the macro ends execution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So all you need to do to get your program to work is define the macro variable BEFORE calling the macro that you want to assign it a value.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So add this line to the top of the program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let tot_c=not known yet ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or add this line to the top of the macro that assigning it a value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if not %symexist(tot_c) %then %global tot_c;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Dec 2023 15:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-was-resolved-but-is-invalid-to-use-in-the-loop-stop/m-p/909022#M358633</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-20T15:43:14Z</dc:date>
    </item>
  </channel>
</rss>

