<?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: How to generate a non-defined macro variable without error messages? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813553#M321103</link>
    <description>&lt;P&gt;When I run your first code I get the following error message.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: File WORK.MYDATA.DATA does not exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, this error message is also absent in my log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortnately it's very difficult for me to rerun the code to regenarate a log with more information.&lt;/P&gt;</description>
    <pubDate>Mon, 16 May 2022 18:21:25 GMT</pubDate>
    <dc:creator>Multipla99</dc:creator>
    <dc:date>2022-05-16T18:21:25Z</dc:date>
    <item>
      <title>How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813501#M321084</link>
      <description>&lt;P&gt;The question below is related to the following answer: &lt;A href="https://communities.sas.com/t5/New-SAS-User/Macro-error-Apparent-symbolic-reference/m-p/561588" target="_blank"&gt;Solved: Macro error Apparent symbolic reference - SAS Support Communities&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an example where code similar to below is run and the WARNING: and ERROR: messages similar to the related question are generated. According to the answer to that question&amp;nbsp;&lt;SPAN&gt;"the only way&amp;nbsp;num_obs is not defined is if the the first query returns no results". &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;However, how should mydata look like, not to generate any value into num_obs and at the same time return no error messages from the proc sql statement. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;My log is very sparse, options nonotes turned on, and therefore I have no information about what the data set looked like at the time of running. It is also very difficult for me to rerun the program to regenerate the error, but nevertheless I need to understand what actually happened.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select count(*) into :num_obs
from (select distinct var
from mydata);
quit;
%let num_obs=&amp;amp;num_obs.;

WARNING: Apparent symbolic reference num_obs not resolved.
ERROR: The text expression &amp;amp;num_obs. contains a recursive reference to the macro variable num_obs. The macro variable will be assigned the null value.

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW: I'm running SAS 9.4 (TS1M6)&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 17:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813501#M321084</guid>
      <dc:creator>Multipla99</dc:creator>
      <dc:date>2022-05-16T17:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813504#M321086</link>
      <description>&lt;P&gt;If I am understanding you properly, this is what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let num_obs=;
proc sql noprint;
    select count(*) into :num_obs
    from (select distinct var
    from mydata);
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 17:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813504#M321086</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-16T17:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813527#M321088</link>
      <description>&lt;P&gt;Note that this statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let num_obs=&amp;amp;num_obs.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is not allowed.&amp;nbsp; As the ERROR message says, the macro language sees this as a recursive reference that it can't handle.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case, I don't think you need a %LET statement at all.&amp;nbsp; I think select count(*) will always return a value and create the macro variable NUM_OBS, unless there is an error in your code.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 17:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813527#M321088</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-05-16T17:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813537#M321092</link>
      <description>&lt;P&gt;There are rare cases where &lt;FONT face="courier new,courier"&gt;count(*)&lt;/FONT&gt; does not return a value. Such as when the variable is not in the data set, which indeed would be a programming error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    select count(*) into :macrovar from (select distinct gorilla from sashelp.class);
quit;
%put &amp;amp;=macrovar;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is always a problem when the user selects tiny portions of the LOG instead of showing us the ENTIRE log for this PROC.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13363"&gt;@Multipla99&lt;/a&gt;&amp;nbsp;show us the ENTIRE log for the PROC of interest next time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 17:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813537#M321092</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-16T17:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813547#M321097</link>
      <description>&lt;P&gt;Thank you, PageMiller, for trying to find the answer to my question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, when I run your code I get the following error message:&lt;/P&gt;
&lt;P&gt;ERROR: The following columns were not found in the contributing tables: gorilla.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have no corresponding error message in my log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Showing the log is of no use to anyone as the program starts with the following:&lt;/P&gt;
&lt;P&gt;options nonotes nomprint nomlogic nosymbolgen nosource nosource2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thus it's only WARNING and ERROR that gets through to the log.&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 18:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813547#M321097</guid>
      <dc:creator>Multipla99</dc:creator>
      <dc:date>2022-05-16T18:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813549#M321099</link>
      <description>&lt;P&gt;Run my first code, not the gorilla code which was just an example where an error occurs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Showing the log is of no use to anyone as the program starts with the following:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;options nonotes nomprint nomlogic nosymbolgen nosource nosource2;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Then issue the opposite command.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options notes source;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;and show us the ENTIRE log for this PROC SQL and macro variable assignment code.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 18:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813549#M321099</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-16T18:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813552#M321102</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Note that this statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let num_obs=&amp;amp;num_obs.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is not allowed.&amp;nbsp; As the ERROR message says, the macro language sees this as a recursive reference that it can't handle.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case, I don't think you need a %LET statement at all.&amp;nbsp; I think select count(*) will always return a value and create the macro variable NUM_OBS, unless there is an error in your code.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is not a recursive reference.&lt;/P&gt;
&lt;P&gt;It is a common method to remove leading/trailing spaces from a macro variable that might have been introduced by using the old CALL SYMPUT() function or by the INTO clause of PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it is easy to remove the need to remove those spaces by not creating to begin with:&lt;/P&gt;
&lt;P&gt;In PROC SQL you can prevent the leading/trailing spaces by added the TRIMMED keyword.&lt;/P&gt;
&lt;P&gt;In DATA step you can prevent the leading/trailing spaces by using the new (15 year old?) CALL SYMPUTX() function instead.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 18:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813552#M321102</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-16T18:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813553#M321103</link>
      <description>&lt;P&gt;When I run your first code I get the following error message.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: File WORK.MYDATA.DATA does not exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, this error message is also absent in my log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortnately it's very difficult for me to rerun the code to regenarate a log with more information.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 18:21:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813553#M321103</guid>
      <dc:creator>Multipla99</dc:creator>
      <dc:date>2022-05-16T18:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813554#M321104</link>
      <description>&lt;P&gt;If you are concerned the define the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example if you are using PROC SQL to define the variable then set some default value before executing the statement that you expect to assign a new value.&amp;nbsp; Then you know the macro variable will exist.&amp;nbsp; And it will also prevent you from using some stale value of the macro variable that was not replaced for some reason.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
%let name=NOT FOUND;
select name into :name trimmed
  from sashelp.class
  where age &amp;gt; 30
;
quit;
%put &amp;amp;=name;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 18:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813554#M321104</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-16T18:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813555#M321105</link>
      <description>&lt;P&gt;You,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13363"&gt;@Multipla99&lt;/a&gt;, in your original code, referred to data set MYDATA. You need to replace this with an actual data set name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Unfortnately it's very difficult for me to rerun the code to regenarate a log with more information.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I don't believe that for a minute. You just ran the code and showed error messages. Just place the options right before your PROC SQL.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 18:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813555#M321105</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-16T18:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813556#M321106</link>
      <description>&lt;P&gt;You can check if a macro variable is defined using %SYMEXIST() function and then define it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if not %symexist(num_obs) %then %do;
  %global num_obs;
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 18:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813556#M321106</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-16T18:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813557#M321107</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Note that this statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let num_obs=&amp;amp;num_obs.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is not allowed.&amp;nbsp; As the ERROR message says, the macro language sees this as a recursive reference that it can't handle.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case, I don't think you need a %LET statement at all.&amp;nbsp; I think select count(*) will always return a value and create the macro variable NUM_OBS, unless there is an error in your code.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is not a recursive reference.&lt;/P&gt;
&lt;P&gt;It is a common method to remove leading/trailing spaces from a macro variable that might have been introduced by using the old CALL SYMPUT() function or by the INTO clause of PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In PROC SQL you and prevent the leading/trailing spaces by added the TRIMMED keyword.&lt;/P&gt;
&lt;P&gt;In DATA step you can prevent the leading/trailing spaces by using the new (15 year old?) CALL SYMPUTX() function instead.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Thanks for the correction&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are of course correct, %let foo=&amp;amp;foo; is only seen as an attempt to create a recursive reference if the macro variable FOO does not exist prior to the execution of this statement.&amp;nbsp; In that case SAS is correctly avoiding the creation of a recursive reference. Indeed I had forgotten that this approach was common before the introduction of TRIMMED.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 18:29:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813557#M321107</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-05-16T18:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813560#M321110</link>
      <description>&lt;P&gt;The problem is not that I want to check if a macro varible exist but rather how I got the messages:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;WARNING: Apparent symbolic reference num_obs not resolved.
ERROR: The text expression &amp;amp;num_obs. contains a recursive reference to the macro variable num_obs. The macro variable will be assigned the null value.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without having any error messages from Proc SQL.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 18:34:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813560#M321110</guid>
      <dc:creator>Multipla99</dc:creator>
      <dc:date>2022-05-16T18:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813561#M321111</link>
      <description>&lt;P&gt;It is easy to do, but not with COUNT().&amp;nbsp; Just run a query that does not return any observations.&amp;nbsp; That does not cause any SQL error,&amp;nbsp; But the INTO never writes to the macro variable since there is nothing to write.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I posted an example earlier.&lt;/P&gt;
&lt;PRE&gt;234  proc sql noprint;
235  %let name=none;
236  select name into :name trimmed from sashelp.class where age&amp;gt;30;
NOTE: No rows were selected.
237  %put &amp;amp;=name;
NAME=none
238  quit;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 18:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813561#M321111</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-16T18:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813562#M321112</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13363"&gt;@Multipla99&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The problem is not that I want to check if a macro varible exist but rather how I got the messages:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;WARNING: Apparent symbolic reference num_obs not resolved.
ERROR: The text expression &amp;amp;num_obs. contains a recursive reference to the macro variable num_obs. The macro variable will be assigned the null value.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without having any error messages from Proc SQL.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;OK, you should still show us the ENTIRE log from PROC SQL, even if there are no errors, which is what I requested.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, if you run my original code, changing MYDATA to the actual data set name, you should get a meaningful result.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 18:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813562#M321112</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-16T18:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813564#M321114</link>
      <description>&lt;P&gt;You may have had earlier errors in the job which caused SAS to enter SYNTAXCHECK mode.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should try to make a little example that reproduces your problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you have shown does not generate the error (if a dataset work.mydata with a variable named VAR) exists:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%symdel num_obs /nowarn;
data mydata ;
  var=1;
run ;
proc sql noprint;
select count(*) into :num_obs
from (select distinct var
from mydata);
quit;
%let num_obs=&amp;amp;num_obs.;
%put &amp;gt;&amp;gt;&amp;amp;num_obs&amp;lt;&amp;lt; ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Even if work.mydata has 0 obs, you don't get an error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%symdel num_obs /nowarn;
data mydata ;
  var=1;
  stop ;
run ;
proc sql noprint;
select count(*) into :num_obs
from (select distinct var
from mydata);
quit;
%let num_obs=&amp;amp;num_obs.;
%put &amp;gt;&amp;gt;&amp;amp;num_obs&amp;lt;&amp;lt; ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The only way I can see to get that error from a macro variable created via count(*) is if MYDATA doesn't exist, or if VAR doesn't exist.&amp;nbsp; But in both of those instances, the SQL step would show an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc delete data=mydata ;
run ;

%symdel num_obs /nowarn;
proc sql noprint;
select count(*) into :num_obs
from (select distinct var
from mydata);
quit;
%let num_obs=&amp;amp;num_obs.;

%put &amp;gt;&amp;gt;&amp;amp;num_obs&amp;lt;&amp;lt; ;


data mydata ;
  othervar=1;
run ;

%symdel num_obs /nowarn;
proc sql noprint;
select count(*) into :num_obs
from (select distinct var
from mydata);
quit;
%let num_obs=&amp;amp;num_obs.;

%put &amp;gt;&amp;gt;&amp;amp;num_obs&amp;lt;&amp;lt; ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 18:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813564#M321114</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-05-16T18:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813568#M321117</link>
      <description>Thank you, Quentin, for the initiated reasoning. &lt;BR /&gt;&lt;BR /&gt;I cannot be sure that mydata or var existed when running. However, I got no error message from Proc SQL so I assume the did. But, then how could I get an empty num_obs? I'm not sure if num_obs existed as a global and/or local macro variable before the proc sql was executed. But I think that the code might have been run within a SAS macro somehow.  &lt;BR /&gt;&lt;BR /&gt;The code is very complex.</description>
      <pubDate>Mon, 16 May 2022 18:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813568#M321117</guid>
      <dc:creator>Multipla99</dc:creator>
      <dc:date>2022-05-16T18:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813570#M321119</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13363"&gt;@Multipla99&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you, Quentin, for the initiated reasoning. &lt;BR /&gt;&lt;BR /&gt;I cannot be sure that mydata or var existed when running. However, I got no error message from Proc SQL so I assume the did. But, then how could I get an empty num_obs? I'm not sure if num_obs existed as a global and/or local macro variable before the proc sql was executed. But I think that the code might have been run within a SAS macro somehow. &lt;BR /&gt;&lt;BR /&gt;The code is very complex.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Another common mistake is to create a LOCAL macro variable and they try to reference it after the macro has ended.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymacro(ds);
proc sql noprint;
select count(*) into :num_obs trimmed from &amp;amp;ds;
quit;
%mend mymacro;

%mymacro(sashelp.class);
%put &amp;amp;=num_obs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can prevent this by just creating the macro variable before calling them macro.&amp;nbsp; Then the INTO clause will write its value into the existing macro variable instead of making a new one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let num_obs=before;
%mymacro(sashelp.class);
%put &amp;amp;=num_obs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;259  %symdel num_obs / nowarn;
260  %mymacro(sashelp.class);
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.01 seconds
      cpu time            0.03 seconds


WARNING: Apparent symbolic reference NUM_OBS not resolved.
261  %put &amp;amp;=num_obs;
num_obs
262
263  %let num_obs=before;
264  %mymacro(sashelp.class);
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


265  %put &amp;amp;=num_obs;
NUM_OBS=19
&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 19:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813570#M321119</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-16T19:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813572#M321120</link>
      <description>There is currently no log from PROC SQL due to the options set in the beginning for the batch of programs.</description>
      <pubDate>Mon, 16 May 2022 19:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813572#M321120</guid>
      <dc:creator>Multipla99</dc:creator>
      <dc:date>2022-05-16T19:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate a non-defined macro variable without error messages?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813575#M321122</link>
      <description>I think you are closing in on the problem, Tom! &lt;BR /&gt;&lt;BR /&gt;There is still, however, one little catch. If the proc sql is run within a SAS macro, the macro variable reference that generates the error message is run within the same macro.</description>
      <pubDate>Mon, 16 May 2022 19:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-generate-a-non-defined-macro-variable-without-error/m-p/813575#M321122</guid>
      <dc:creator>Multipla99</dc:creator>
      <dc:date>2022-05-16T19:08:49Z</dc:date>
    </item>
  </channel>
</rss>

