<?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 Juletip #2 - Avoid macro in SAS Community Nordic</title>
    <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-2-Avoid-macro/m-p/518320#M193</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The Macro language is powerfull, but sometimes it would be nice if you could avoid making a macro, just to make a small part of your code conditional&lt;/STRONG&gt;. &lt;STRONG&gt;For example: when your program should delete a tabel - but only if it exist (to avoid warnings in the log).&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put Warnings if you drop a a table that doesnt exist;
proc sql ;
   drop table WORK.CLASS;
quit;
 
options mprint;
%put Method 1 (Old school): wrap the code in a macro deleting the table if it exists - call macro;
 
%macro mymacro;
%if %sysfunc(exist(WORK.CLASS)) %then
   %do;
      proc sql ;
         drop table WORK.CLASS;
      quit;
   %end;
%mend;
 
%mymacro;
 
***Same but simpler (no macro definition) using SAS function IFC.;
%put Method 2: use IFC - avoid new macro;
 
proc sql ;
   %sysfunc(IFC(%sysfunc(exist(WORK.CLASS)), drop table WORK.CLASS, )); ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;Also&lt;/STRONG&gt; with SAS 9.4 Maintenance 5 &lt;/SPAN&gt;&lt;SPAN&gt;You can now &lt;/SPAN&gt;&lt;A href="http://go.documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n18fij8dqsue9pn1lp8436e5mvb7.htm&amp;amp;locale=en"&gt;use %IF-%THEN-%ELSE constructs in open code&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2018/07/05/if-then-else-sas-programs/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2018/07/05/if-then-else-sas-programs/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put Method 3: SAS 9.4M5 only - use in open code;

%if %sysfunc(exist(WORK.CLASS)) %then
   %do;
      proc sql ;
         drop table WORK.CLASS;
      quit;
   %end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Dec 2018 07:53:03 GMT</pubDate>
    <dc:creator>JesperMusaeus</dc:creator>
    <dc:date>2018-12-04T07:53:03Z</dc:date>
    <item>
      <title>Juletip #2 - Avoid macro</title>
      <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-2-Avoid-macro/m-p/518320#M193</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The Macro language is powerfull, but sometimes it would be nice if you could avoid making a macro, just to make a small part of your code conditional&lt;/STRONG&gt;. &lt;STRONG&gt;For example: when your program should delete a tabel - but only if it exist (to avoid warnings in the log).&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put Warnings if you drop a a table that doesnt exist;
proc sql ;
   drop table WORK.CLASS;
quit;
 
options mprint;
%put Method 1 (Old school): wrap the code in a macro deleting the table if it exists - call macro;
 
%macro mymacro;
%if %sysfunc(exist(WORK.CLASS)) %then
   %do;
      proc sql ;
         drop table WORK.CLASS;
      quit;
   %end;
%mend;
 
%mymacro;
 
***Same but simpler (no macro definition) using SAS function IFC.;
%put Method 2: use IFC - avoid new macro;
 
proc sql ;
   %sysfunc(IFC(%sysfunc(exist(WORK.CLASS)), drop table WORK.CLASS, )); ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;Also&lt;/STRONG&gt; with SAS 9.4 Maintenance 5 &lt;/SPAN&gt;&lt;SPAN&gt;You can now &lt;/SPAN&gt;&lt;A href="http://go.documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n18fij8dqsue9pn1lp8436e5mvb7.htm&amp;amp;locale=en"&gt;use %IF-%THEN-%ELSE constructs in open code&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2018/07/05/if-then-else-sas-programs/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2018/07/05/if-then-else-sas-programs/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put Method 3: SAS 9.4M5 only - use in open code;

%if %sysfunc(exist(WORK.CLASS)) %then
   %do;
      proc sql ;
         drop table WORK.CLASS;
      quit;
   %end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Dec 2018 07:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-2-Avoid-macro/m-p/518320#M193</guid>
      <dc:creator>JesperMusaeus</dc:creator>
      <dc:date>2018-12-04T07:53:03Z</dc:date>
    </item>
  </channel>
</rss>

