<?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 stop part of query if dataset is empty in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780693#M248773</link>
    <description>&lt;P&gt;That worked like a charm!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for helping me. Have a great day!&lt;/P&gt;</description>
    <pubDate>Wed, 17 Nov 2021 09:35:09 GMT</pubDate>
    <dc:creator>wixol87</dc:creator>
    <dc:date>2021-11-17T09:35:09Z</dc:date>
    <item>
      <title>How to stop part of query if dataset is empty</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780682#M248764</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some SAS-jobs that runs each evening that creates datasets that is used to update dashboards. These tables are appended to already existing datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sometimes something in these SAS-jobs goes wrong so the datasets is empty, often because there are some capacity issues in the central systems that makes some queries run empty. And if these empty datasets then are appended, then the dashboards shows nothing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would rather have a day old data in the dashboards then no data at all and hope the sas-jobs runs fine the next day. I can't find good examples that helps me with what I'm trying to achieve.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So how can I stop the appending of empty datasets, but also let the code below this appending continue to run?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if obs &amp;gt; 0 in new_dataset then do;&lt;/P&gt;&lt;P&gt;proc sql; delete from Server.old_dataset; quit;&lt;/P&gt;&lt;P&gt;proc append base=Server.old_dataset data=new_dataset;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 07:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780682#M248764</guid>
      <dc:creator>wixol87</dc:creator>
      <dc:date>2021-11-17T07:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop part of query if dataset is empty</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780683#M248765</link>
      <description>&lt;P&gt;Retrieve the obs number from DICTIONARY.TABLES, and use it in a macro condition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nobs = 0; /* in case dataset does not exist at all */
proc sql noprint;
select nobs into :nobs from dictionary.tables
where libname = "WORK" and mename = "NEW_DATASET"; /* upper case here! */
quit;

%if &amp;amp;nobs. gt 0
%then %do;
/* remaining code */
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Nov 2021 07:20:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780683#M248765</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-17T07:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop part of query if dataset is empty</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780686#M248767</link>
      <description>Hi.&lt;BR /&gt;Thanks for answering.&lt;BR /&gt;&lt;BR /&gt;I see that the first part of your code runs smoothly and I get a output in the macro. I however get the error-message below on the %IF-statement, and I see that the code I have in the "remaining code" runs whether or not the macro is 0 or greater than 0:&lt;BR /&gt;&lt;BR /&gt;ERROR: The %IF statement is not valid in open code.&lt;BR /&gt;27&lt;BR /&gt;28 %if &amp;amp;nobs. gt 0&lt;BR /&gt;29 %then %do;</description>
      <pubDate>Wed, 17 Nov 2021 07:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780686#M248767</guid>
      <dc:creator>wixol87</dc:creator>
      <dc:date>2021-11-17T07:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop part of query if dataset is empty</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780687#M248768</link>
      <description>&lt;P&gt;Have your SAS admins update to the current maintenance level 3 days before yesterday. There are so many goodies in there (including the use of %IF %THEN %DO %END in "open code") that not updating (which only takes some work, updates are included in your license) is simply dumb.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having said that, you need to wrap it into a macro for the time being:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rest_of_code;
%if &amp;amp;nobs. gt 0
%then %do;
/* remaining code */
%end;
%mend;
%rest_of_code&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Nov 2021 08:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780687#M248768</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-17T08:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop part of query if dataset is empty</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780691#M248771</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279973"&gt;@wixol87&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is not responding "1-on-1" on your request, but maybe you can use "exit" functionality in your macro.&lt;/P&gt;
&lt;P&gt;I like it and use it from time-to-time.&lt;/P&gt;
&lt;DIV id="n1wf7o7dw8oq9en1qyqm3g2lwlcd" class="xisDoc-exampleBlock"&gt;
&lt;H2 class="xisDoc-title"&gt;Example: Providing Exits in a Large &lt;FONT&gt;Macro&lt;/FONT&gt;&lt;/H2&gt;
&lt;DIV class="xisDoc-example"&gt;
&lt;P class="xisDoc-paragraph"&gt;The %GOTO statement is useful in large macros when you want to provide an &lt;FONT&gt;exit&lt;/FONT&gt; if an error occurs.&lt;/P&gt;
&lt;DIV id="n0lyod6c3cs4h9n1jukvaxu8sy2o" class="xisDoc-codeBlock"&gt;
&lt;DIV class="xisDoc-codeBlockCode"&gt;
&lt;DIV class="xis-copyToClipboardBtn"&gt;
&lt;PRE class="xisDoc-code"&gt;&lt;CODE&gt;%&lt;FONT&gt;macro&lt;/FONT&gt; check(parm);
   %local status;
   %if &amp;amp;parm= %then %do;
       %put ERROR:  You must supply a parameter to &lt;FONT&gt;macro&lt;/FONT&gt; CHECK.;
       %goto &lt;FONT&gt;exit&lt;/FONT&gt;;
   %end;
   &lt;EM class="xisDoc-userSuppliedValue"&gt;more &lt;FONT&gt;macro&lt;/FONT&gt; statements that test for error conditions &lt;/EM&gt;
   %if &amp;amp;status &amp;gt; 0 %then %do;
       %put ERROR:  File is empty.;
       %goto &lt;FONT&gt;exit&lt;/FONT&gt;;
   %end;
   &lt;EM class="xisDoc-userSuppliedValue"&gt;more &lt;FONT&gt;macro&lt;/FONT&gt; statements that generate text &lt;/EM&gt;
   %put Check completed successfully.;
%&lt;FONT&gt;exit&lt;/FONT&gt;: %mend check;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 09:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780691#M248771</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-11-17T09:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop part of query if dataset is empty</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780693#M248773</link>
      <description>&lt;P&gt;That worked like a charm!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for helping me. Have a great day!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 09:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780693#M248773</guid>
      <dc:creator>wixol87</dc:creator>
      <dc:date>2021-11-17T09:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop part of query if dataset is empty</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780694#M248774</link>
      <description>&lt;P&gt;Thanks for this. I'll have it in mind if a come across a problem where this could be useful &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 09:36:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-part-of-query-if-dataset-is-empty/m-p/780694#M248774</guid>
      <dc:creator>wixol87</dc:creator>
      <dc:date>2021-11-17T09:36:08Z</dc:date>
    </item>
  </channel>
</rss>

