<?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: Execute Conditional SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Execute-Conditional-SQL/m-p/751556#M236597</link>
    <description>&lt;P&gt;I need to use the "Replace" method when I'm going to read the first file, and the "Append to Existing" method in the others.&lt;/P&gt;&lt;P&gt;I had the idea to use "Append to Existing" and delete the table when I detected the reading of the first file.&amp;nbsp;the code worked, however it had a problem with the table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro APAGA;
/*proc sql;
	DELETE FROM RECEITA.ESTABELECIMENTOS;
	run;*/
	data RECEITA.ESTABELECIMENTOS;
	set RECEITA.ESTABELECIMENTOS (obs=0);
	run;
	
quit;

data _null_;
	IF instr(&amp;amp;Arq,"Y0.")&amp;gt;0 then call execute('%APAGA');
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I managed to solve it in another way, now I have two Jobs, one with the Append option and the other with Replace, I choose between one and the other in a third job.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60891i2B1712DC72E3AA12/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Jul 2021 19:39:11 GMT</pubDate>
    <dc:creator>fabiopjr</dc:creator>
    <dc:date>2021-07-01T19:39:11Z</dc:date>
    <item>
      <title>Execute Conditional SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-Conditional-SQL/m-p/751325#M236497</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to execute a SQL only if the name of a file contains the expression y0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME RECEITA BASE "G:\RECEITA";
IF instr(&amp;amp;Arq,"Y0.")&amp;gt;0 then call execute(
	"Proc sql;
	DELETE FROM RECEITA.ESTABELECIMENTOS;")
	RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But&amp;nbsp; generats error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="team.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60862iC6566B5B1C1B2CFA/image-size/large?v=v2&amp;amp;px=999" role="button" title="team.png" alt="team.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;How can I solve this?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 18:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-Conditional-SQL/m-p/751325#M236497</guid>
      <dc:creator>fabiopjr</dc:creator>
      <dc:date>2021-06-30T18:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Conditional SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-Conditional-SQL/m-p/751345#M236508</link>
      <description>&lt;P&gt;Your IF statement must be in a DATA step. It will not work otherwise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you still have other problems preventing this from working. If your logic is to find the value "Y0." (that's three characters, a capital Y, a zero and a dot, in sequence) somewhere in variable &amp;amp;arq (but you haven't defined &amp;amp;arq), then you still have a problem that there is no INSTR function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, please, describe in words (not SAS code) exactly (and I mean in detail, step-by-step, leaving nothing out) what you are trying to do.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 19:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-Conditional-SQL/m-p/751345#M236508</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-30T19:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Conditional SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-Conditional-SQL/m-p/751556#M236597</link>
      <description>&lt;P&gt;I need to use the "Replace" method when I'm going to read the first file, and the "Append to Existing" method in the others.&lt;/P&gt;&lt;P&gt;I had the idea to use "Append to Existing" and delete the table when I detected the reading of the first file.&amp;nbsp;the code worked, however it had a problem with the table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro APAGA;
/*proc sql;
	DELETE FROM RECEITA.ESTABELECIMENTOS;
	run;*/
	data RECEITA.ESTABELECIMENTOS;
	set RECEITA.ESTABELECIMENTOS (obs=0);
	run;
	
quit;

data _null_;
	IF instr(&amp;amp;Arq,"Y0.")&amp;gt;0 then call execute('%APAGA');
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I managed to solve it in another way, now I have two Jobs, one with the Append option and the other with Replace, I choose between one and the other in a third job.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60891i2B1712DC72E3AA12/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 19:39:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-Conditional-SQL/m-p/751556#M236597</guid>
      <dc:creator>fabiopjr</dc:creator>
      <dc:date>2021-07-01T19:39:11Z</dc:date>
    </item>
  </channel>
</rss>

