<?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: Understanding macro logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Understanding-macro-logic/m-p/643507#M192058</link>
    <description>&lt;P&gt;This macro code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysfunc (exist(score_result))
%then insert into score_result;
%else create table score_result as;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;alternatively either creates the &lt;EM&gt;text&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;insert into score_result&lt;/PRE&gt;
&lt;P&gt;or the &lt;EM&gt;text&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;create table score_result as&lt;/PRE&gt;
&lt;P&gt;which then, after being fed to the SQL compiler, results in two variants of the SQL &lt;EM&gt;statement&lt;/EM&gt;.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Apr 2020 10:39:49 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-04-28T10:39:49Z</dc:date>
    <item>
      <title>Understanding macro logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-macro-logic/m-p/643495#M192048</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the code below, please can someone explain the logic (highlighted in red text below)? I'm confused about why the same "score_result" is used for if/then and else?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;%if %sysfunc (exist(score_result))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %then insert into&amp;nbsp;score_result;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %else create table&amp;nbsp;score_result&lt;/FONT&gt; as;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select * from test;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I wanted to permanently save into a permanently library, with libref "ac", would the code be the options below, or something else?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Option 1&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#000000"&gt;%if %sysfunc (exist(score_result))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %then insert into &lt;FONT color="#FF0000"&gt;ac.&lt;/FONT&gt;score_result;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %else create table &lt;FONT color="#FF0000"&gt;ac.&lt;/FONT&gt;score_result as;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select * from test;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Option 2&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#000000"&gt;%if %sysfunc (exist(score_result))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %then insert into&lt;/FONT&gt; &lt;FONT color="#000000"&gt;score_result;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %else create table &lt;FONT color="#FF0000"&gt;ac.&lt;/FONT&gt;score_result as;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select * from test;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Option 3&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#000000"&gt;%if %sysfunc (exist(&lt;FONT color="#FF0000"&gt;ac.&lt;/FONT&gt;score_result))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %then insert into&lt;/FONT&gt; &lt;FONT color="#000000"&gt;&lt;FONT color="#FF0000"&gt;ac.&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#000000"&gt;score_result;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %else create table &lt;FONT color="#FF0000"&gt;ac.&lt;/FONT&gt;score_result as;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select * from test;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 10:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-macro-logic/m-p/643495#M192048</guid>
      <dc:creator>Justin9</dc:creator>
      <dc:date>2020-04-28T10:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding macro logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-macro-logic/m-p/643497#M192050</link>
      <description>&lt;P&gt;I would think that you'd want an option 3:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Option 3

proc sql;
       %if %sysfunc (exist(ac.score_result))
                %then insert into ac.score_result;
                %else create table ac.score_result as;
       select * from test;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 10:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-macro-logic/m-p/643497#M192050</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2020-04-28T10:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding macro logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-macro-logic/m-p/643507#M192058</link>
      <description>&lt;P&gt;This macro code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysfunc (exist(score_result))
%then insert into score_result;
%else create table score_result as;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;alternatively either creates the &lt;EM&gt;text&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;insert into score_result&lt;/PRE&gt;
&lt;P&gt;or the &lt;EM&gt;text&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;create table score_result as&lt;/PRE&gt;
&lt;P&gt;which then, after being fed to the SQL compiler, results in two variants of the SQL &lt;EM&gt;statement&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 10:39:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-macro-logic/m-p/643507#M192058</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-28T10:39:49Z</dc:date>
    </item>
  </channel>
</rss>

