<?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 Variable %Symexist in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Symexist/m-p/489841#M127990</link>
    <description>&lt;P&gt;Thank you tom and astounding&lt;/P&gt;</description>
    <pubDate>Sat, 25 Aug 2018 18:53:51 GMT</pubDate>
    <dc:creator>sameer112217</dc:creator>
    <dc:date>2018-08-25T18:53:51Z</dc:date>
    <item>
      <title>Macro Variable %Symexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Symexist/m-p/489819#M127975</link>
      <description>&lt;P&gt;data sample;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data sample1;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;select&amp;nbsp; memname into :deletelist seperated by ' '&lt;BR /&gt;from dictionary.tables where&lt;BR /&gt;libname = "WORK";&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%global deletelist;&lt;BR /&gt;%put &amp;amp;deletelist;&lt;BR /&gt;&lt;BR /&gt;%symdel deletelist;&lt;BR /&gt;&lt;BR /&gt;%Macro deletetables;&lt;BR /&gt;%if %symexist (deletelist) %then %do;&lt;BR /&gt;Proc datasets library= work nolist;&lt;BR /&gt;delete &amp;amp;deletelist;&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%put The macro variable deletelist does not exsit;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%mend deletetables;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%deletetables;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the above examples I am keeping this piece of program in my job flow. This is just an example to what the logic I need for my project. When macro variable deletelist is created it has two values sample sample1 when you run first time but when it is deleted and the next time you run the same program I get the message with an error. "WARNING: Apparent symbolic reference DELETELIST not resolved" because there is no values in the macro variable now and it is already deleted when the program ran first time, how can I resolve this with other method/logic to avoid error? Does %symexist function check the existence of macro variable? I tried %sysfunc(exist but it doesn't work in case of macro variable like this.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Aug 2018 12:59:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Symexist/m-p/489819#M127975</guid>
      <dc:creator>sameer112217</dc:creator>
      <dc:date>2018-08-25T12:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable %Symexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Symexist/m-p/489820#M127976</link>
      <description>&lt;P&gt;If you want to check whether a macro variable exists, you can examine dictionary.macros.&amp;nbsp; But there is an approach that is both easier and better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You already guarantee that the variable does exist by issuing this statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%global deletelist;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So leave it there.&amp;nbsp; Don't get rid of it by issuing the %SYMDEL command.&amp;nbsp; Instead, check to see whether it contains anything.&amp;nbsp; (After all, if the macro variable exists, but has a null value, you should skip PROC DATASETS.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In practice, this means changing this logic:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;%if %symexist (deletelist) %then %do;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Proc datasets library= work nolist;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;delete &amp;amp;deletelist;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The replacement logic:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;%if %length(&amp;amp;deletelist) %then %do;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Proc datasets library= work nolist;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;delete &amp;amp;deletelist;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;%let deletelist=;&lt;BR /&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%ELSE is no longer needed, unless you just want to write a message:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%else %put No data sets were deleted.;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Aug 2018 14:18:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Symexist/m-p/489820#M127976</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-25T14:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable %Symexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Symexist/m-p/489835#M127986</link>
      <description>&lt;P&gt;Your logic is over complicated as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;has already answered.&lt;/P&gt;
&lt;P&gt;But the reason the macro variable was not created is because of how PROC SQL works. When the result set has no observations then the macro variable is not created.&lt;/P&gt;
&lt;P&gt;An easy way to handle this fact is to get in the habit of setting a default value with a %LET statement before the SELECT statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint ;
%let deletelist=;
select nliteral(memname)
  into :deletelist seperated by ' '
  from dictionary.tables 
  where libname = "WORK"
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also test the automatic macro variable SQLOBS after the select statement.&lt;/P&gt;
&lt;P&gt;For example you might change how you are using the macro variable so that it contains the whole DELETE statement instead of just the list of names.&amp;nbsp; Then there is no need for macro logic (or a macro) at the actual delete step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint ;
%let deletelist=;
select nliteral(memname)
  into :deletelist seperated by ' '
  from dictionary.tables 
  where libname = "WORK"
;
%let deletelist=%sysfunc(ifc(&amp;amp;sqlobs,delete &amp;amp;deletelist,%str( )));
quit;
...
proc datasets lib="WORK" nolist;
&amp;amp;deletelist;
run; quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Aug 2018 17:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Symexist/m-p/489835#M127986</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-25T17:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable %Symexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Symexist/m-p/489841#M127990</link>
      <description>&lt;P&gt;Thank you tom and astounding&lt;/P&gt;</description>
      <pubDate>Sat, 25 Aug 2018 18:53:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Symexist/m-p/489841#M127990</guid>
      <dc:creator>sameer112217</dc:creator>
      <dc:date>2018-08-25T18:53:51Z</dc:date>
    </item>
  </channel>
</rss>

