<?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: Checking nobs for an empty dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793240#M254213</link>
    <description>FYI, I intend to include endsas for when the program is run automatically once a month - that is why I want an email when there are zero observations.</description>
    <pubDate>Fri, 28 Jan 2022 23:34:43 GMT</pubDate>
    <dc:creator>kz_</dc:creator>
    <dc:date>2022-01-28T23:34:43Z</dc:date>
    <item>
      <title>Checking nobs for an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793179#M254182</link>
      <description>&lt;P&gt;I am reading this blog post:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sgf/2021/03/24/how-to-conditionally-stop-sas-code-execution-and-gracefully-terminate-sas-session/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2021/03/24/how-to-conditionally-stop-sas-code-execution-and-gracefully-terminate-sas-session/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I copied the code directly from the blog (changed the dataset name to my data), but it doesn't work. Can anyone tell me why? The error in the log is:&amp;nbsp;&lt;/P&gt;
&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogError1_1643392637984" class="sasError"&gt;ERROR: Invalid sequence of commands for file WORK.CLAIMS.DATA.&lt;/DIV&gt;
&lt;DIV id="sasLogNote1_1643392637984" class="sasNote"&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/DIV&gt;
&lt;DIV id="sasLogNote2_1643392637984" class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;
&lt;PRE&gt;data _null_;
   if 0 then set claims nobs=n;
   if n=0 then
   do;
      put 'NOTE: No suspicious cases were found. Further processing is terminated.';
      call execute('endsas;');
   end;
   stop;
run;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;The whole reason I'm reading this blog is that I want to check if a dataset read in from a proc iml step has zero observations. If so, I want to send an email to myself, and if not, I want to continue the program. So any recommendations on a nice way to do that would be appreciated.&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Fri, 28 Jan 2022 18:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793179#M254182</guid>
      <dc:creator>kz_</dc:creator>
      <dc:date>2022-01-28T18:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Checking nobs for an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793204#M254194</link>
      <description>&lt;P&gt;Please share the actual log lines that generate that error.&amp;nbsp; It almost sounds like there is an issue with the CLAIMS dataset itself and not with your program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that running ENDSAS will not work well if you are using SAS/Studio, Enterprise Guide or some other tool that runs SAS in the background for you. It will literal end the SAS session and the front-end program that send that code to SAS will not be able to show you the LOG or anything else.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 19:58:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793204#M254194</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-28T19:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: Checking nobs for an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793210#M254197</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not see an ERROR in your code. Show us the LOG!&lt;BR /&gt;I also check the number of observations in a data set that way.&lt;BR /&gt;It is a very performant | quick check as it only checks the header portion of the data set (containing the metadata). No record is read!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.claims;
length record $ 250;
if 0;
run;

data _NULL_;
 if 0 then set work.claims nobs=count;
 call symputx('numobs',put(count,8.));
 STOP;
run;
%PUT &amp;amp;=numobs;&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;See also here for the e-mail part of your question :&lt;/P&gt;
&lt;P&gt;How to send email using SAS?&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-send-email-using-SAS/ta-p/746523" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-send-email-using-SAS/ta-p/746523&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 20:08:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793210#M254197</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-01-28T20:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Checking nobs for an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793239#M254212</link>
      <description>&lt;P&gt;Claims is a dataset with all desired variables but no observations. Here are all of the log lines after deleting the endsas statement (log is the same either way):&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;68&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;69 data _null_;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;70 if 0 then set claims nobs=n;&lt;/DIV&gt;
&lt;DIV id="sasLogError1_1643412711591" class="sasError"&gt;ERROR: File WORK.CLAIMS.DATA does not exist.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;71 if n=0 then&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;72 do;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;73 put 'NOTE: No suspicious cases were found. Further processing is terminated.';&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;74&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;75 end;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;76 stop;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;77 run;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogNote1_1643412711591" class="sasNote"&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/DIV&gt;
&lt;DIV id="sasLogNote2_1643412711591" class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;78&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;79 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;</description>
      <pubDate>Fri, 28 Jan 2022 23:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793239#M254212</guid>
      <dc:creator>kz_</dc:creator>
      <dc:date>2022-01-28T23:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: Checking nobs for an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793240#M254213</link>
      <description>FYI, I intend to include endsas for when the program is run automatically once a month - that is why I want an email when there are zero observations.</description>
      <pubDate>Fri, 28 Jan 2022 23:34:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793240#M254213</guid>
      <dc:creator>kz_</dc:creator>
      <dc:date>2022-01-28T23:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: Checking nobs for an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793241#M254214</link>
      <description>&lt;P&gt;Mostly I was just curious about why the code above doesn't work. I assume it should be correct since it's from a SAS blog post. Anyway, I got my code to work using proc sql count:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql; 
select count(*) into :n_claims from claims; 
quit;

%if &amp;amp;n_claims = 0 %then %do; 
[things to do];
%end;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jan 2022 23:39:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793241#M254214</guid>
      <dc:creator>kz_</dc:creator>
      <dc:date>2022-01-28T23:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: Checking nobs for an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793242#M254215</link>
      <description>&lt;P&gt;Maybe something is missing here. The first data step erases all the observations when there are observations, and the second one produces the same error as the original code (if I don't run the first data step).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;68&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;69 data _NULL_;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;70 if 0 then set work.claims nobs=count;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;71 call symputx('numobs',put(count,8.));&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;72 STOP;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;73 run;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogError1_1643413825198" class="sasError"&gt;ERROR: Invalid sequence of commands for file WORK.CLAIMS.DATA.&lt;/DIV&gt;
&lt;DIV id="sasLogNote1_1643413825198" class="sasNote"&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/DIV&gt;
&lt;DIV id="sasLogNote2_1643413825198" class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogWarning1_1643413825198" class="sasWarning"&gt;WARNING: Apparent symbolic reference NUMOBS not resolved.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;74 %PUT &amp;amp;=numobs;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;numobs&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;75&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;76&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;77 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;87&lt;/DIV&gt;</description>
      <pubDate>Fri, 28 Jan 2022 23:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793242#M254215</guid>
      <dc:creator>kz_</dc:creator>
      <dc:date>2022-01-28T23:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Checking nobs for an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793245#M254216</link>
      <description>&lt;P&gt;You have posted two contradictory logs.&lt;/P&gt;
&lt;P&gt;The previous one is showing an error because this is no WORK.CLAIMS dataset to set.&lt;/P&gt;
&lt;P&gt;This one is showing a strange error that seems to indicate WORK.CLAIMS exists, but is not a valid dataset.&amp;nbsp; Or perhaps it is a VIEW that generates an error?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general to fix some of these things the simple idea is to set your macro variable to whatever your FAIL condition is. Then do the test and if it does not change the value that you still ahve something to test.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nobs=0;
data _null_;
  call symputx('nobs',nobs);
  stop;
  set claims nobs=nobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If if you are running a recent enough version of SAS use some open code %IF %THEN %DO END.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysfunc(exist(work.claims)) %then %do;
data _null_;
  call symputx('nobs',nobs);
  stop;
  set claims nobs=nobs;
run;
%end;
%else %do;
%let nobs=0;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Jan 2022 02:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793245#M254216</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-29T02:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Checking nobs for an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793246#M254217</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/322176"&gt;@kz_&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your initial code works for me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A select count(*) will also work but needs to travers through the whole table which for a big table will impact on performance. You can for SAS tables query the dictionary tables instead. This doesn't require processing the data and though performance is independent of table size.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n_claims=;
proc sql; 
  select nlobs into :n_claims 
  from dictionary.tables 
  where libname='WORK' and memname='CLAIMS';
quit;

%if &amp;amp;n_claims = 0 %then %do; 
[things to do];
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm querying in above code NLOBS and not NOBS. NLOBS will return the number of non-deleted observations in a SAS table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If deleting rows in a table using Proc SQL Delete then rows get only logically deleted and NOBS would return a "wrong" count.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jan 2022 02:25:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793246#M254217</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-01-29T02:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: Checking nobs for an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793276#M254233</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/322176"&gt;@kz_&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I erase all observations on purpose (to have zero observations).&lt;/P&gt;
&lt;P&gt;The 2nd data-step should work fine.&lt;BR /&gt;I can submit it over here.&lt;/P&gt;
&lt;P&gt;Very weird!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jan 2022 10:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-nobs-for-an-empty-dataset/m-p/793276#M254233</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-01-29T10:49:02Z</dc:date>
    </item>
  </channel>
</rss>

