<?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 test for zero observations and still be in control in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/258659#M49871</link>
    <description>&lt;P&gt;I use something like this. &amp;nbsp;If the data is empty add one obs and check for a missing variable in COMPUTE AFTER; &amp;nbsp;MODIFY keeps from breaking the data when it HAS obs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: 24MAR2015 My example data has ONE obs but should have ZERO so the MODIFY is not adding an observations with all missing values. &amp;nbsp;The output statement in the first data step should be removed to model the exact scenario. &amp;nbsp;The PROC REPORT works the same either way no matter how the "one all missing obs data set is created".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This method has can be modified to function at the end of a breaking variable not just at end of report. &amp;nbsp;I have used this technique in BIMO listings where I want a message "No data for this study site: &amp;lt;siteid&amp;gt;" &amp;nbsp; the site records are created by merging&amp;nbsp;the listing data with a list (data set) of all sites.&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;data class;
   *output; to model the zero obs scenario;
   stop;
   set sashelp.class;
   run;
*Add one obs to class if it is empty;
data class;
   if eof then output;
   stop;
   modify class end=eof;
   run;
options missing=' ';
proc report data=class list missing;
   columns _all_;
   define name / order;
   compute after name;
      msg = 'No data for this report.';
      l = length(msg);
      if not missing(name) then l=0;
      line msg $varying. l;
      endcomp;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2444iBB52DF02A1507990/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Mar 2016 12:51:03 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2016-03-24T12:51:03Z</dc:date>
    <item>
      <title>How to test for zero observations and still be in control</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/80447#M17330</link>
      <description>&lt;P&gt;I recently came across a situation where an input data set had zero observations. Those things happen, but it should be reported loud and clear in the log or by sending an email to a responsible analyst.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My first reaction was to do it straight forward, like in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA OutputSet;
SET InputSet NOBS=nobs;
IF nobs = 0 then 
  PUTLOG "!!!!!!!!!!! Empty input data set !!!!!!!!!';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, that does not work. SAS reaches end of input before it ever reaches the IF statement and nothing is sent to the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep in mind that the nobs variable receives its value during the compilation phase. So you can test it's contents before executing the SET statement. So the solution is simple: move the IF statement before the SET statement. This is the result in the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;422&amp;nbsp; DATA OutputSet;
423&amp;nbsp; IF nobs = 0 then PUTLOG '!!!!!!!!!!! Empty input data set !!!!!!!!!';
424&amp;nbsp; SET InputSet NOBS=nobs;
425&amp;nbsp; RUN;

!!!!!!!!!!! Empty input data set !!!!!!!!!

NOTE: There were 0 observations read from the data set WORK.INPUTSET.
NOTE: The data set WORK.OUTPUTSET has 0 observations and 2 variables.
NOTE: DATA statement used (Total process time):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is obvious that you could replace the PUTLOG statement by anything, including sending mail.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 13:59:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/80447#M17330</guid>
      <dc:creator>ErikT</dc:creator>
      <dc:date>2018-01-12T13:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to test for zero observations and still be in control</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/80448#M17331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To make this more useful, make your statement start with "ERROR:" or "WARNING:' Then the text in the log will have the assigned colors for error or warning messages, at least in interactive mode.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 16:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/80448#M17331</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-09-12T16:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to test for zero observations and still be in control</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/80449#M17332</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for sharing. Here is a complete code that combines ballardw's comment with ErikT's tip.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Proc Sql;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Create an empty table. */&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Create Table InputSet (x Char(8));&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Quit;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;DATA _null_;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET InputSet NOBS=nobs;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF nobs = 0 then PUT "ERROR:&amp;nbsp; InputSet Table is empty";&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Doesn't work. */&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;RUN;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;DATA _null_;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF nobs = 0 then PUT "ERROR:&amp;nbsp; InputSet Table is empty";&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Works. */&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET InputSet NOBS=nobs;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;RUN;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But, a better way to check if a table has zero rows would be to use Proc Datasets as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc Sql; /* Create an empty table. */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Create Table InputSet (x Char(8));&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc datasets nolist;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; contents DATA=work.InputSet out=temp(Keep=NOBS) noprint;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Data _Null_;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set temp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If NOBS = 0 Then Put "ERROR: Table is empty.";&lt;BR /&gt;Run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 17:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/80449#M17332</guid>
      <dc:creator>Jakkas</dc:creator>
      <dc:date>2013-09-12T17:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to test for zero observations and still be in control</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/80450#M17333</link>
      <description>&lt;P&gt;NOBS may not be the most reliable source of 0 records.&amp;nbsp; Also if you want to use WHERE subset then EOF is a better indicator of "will there be any data?"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using FILEVAR file statement option allows data step to send e-mail conditionally.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; 
   if eof then do; 
      id = "&amp;amp;sysuserid@yourdomain.com"; 
      length indsname $64; 
      file dummy email filevar=id;
      put "!EM_SUBJECT! INFO from &amp;amp;_CLIENTPROJECTNAME &amp;amp;_CLIENTTASKLABEL"; 
      PUT 'ERROR: Input Table ' indsname 'is empty'; 
      end; 
   stop; 
   set sashelp.class INDSNAME=INDSNAME end=eof;
   where sex eq 'S'; 
   run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13591"&gt;@ErikT&lt;/a&gt;&amp;nbsp;wrote:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I recently came across a situation where an input data set had zero observations. Those things happen, but it should be reported loud and clear in the log or by sending an email to a responsible analyst.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My first reaction was to do it straight forward, like in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;DATA&lt;/SPAN&gt; OutputSet&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;SET&lt;/SPAN&gt; InputSet NOBS&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;nobs&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;IF&lt;/SPAN&gt; nobs &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; 
  &lt;SPAN class="token function"&gt;PUTLOG&lt;/SPAN&gt; "&lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;!&lt;/SPAN&gt; Empty &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;!&lt;/SPAN&gt;'&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;RUN&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, that does not work. SAS reaches end of input before it ever reaches the IF statement and nothing is sent to the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep in mind that the nobs variable receives its value during the compilation phase. So you can test it's contents before executing the SET statement. So the solution is simple: move the IF statement before the SET statement. This is the result in the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;422&amp;nbsp; DATA OutputSet;
423&amp;nbsp; IF nobs = 0 then PUTLOG '!!!!!!!!!!! Empty input data set !!!!!!!!!';
424&amp;nbsp; SET InputSet NOBS=nobs;
425&amp;nbsp; RUN;

!!!!!!!!!!! Empty input data set !!!!!!!!!

NOTE: There were 0 observations read from the data set WORK.INPUTSET.
NOTE: The data set WORK.OUTPUTSET has 0 observations and 2 variables.
NOTE: DATA statement used (Total process time):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is obvious that you could replace the PUTLOG statement by anything, including sending mail.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 14:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/80450#M17333</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-01-12T14:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to test for zero observations and still be in control</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/80451#M17334</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/default/viewer.htm#p1o13d7wb2zfcnn19s5ssl2zdxvi.htm" title="http://support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/default/viewer.htm#p1o13d7wb2zfcnn19s5ssl2zdxvi.htm"&gt;SAS(R) 9.3 Macro Language: Reference&lt;/A&gt; (%sysfunc --&amp;nbsp; Example 5: Determining the Number of Variables and Observations in a Data)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let dsid = %sysfunc( open(myDataSet) ); &lt;/P&gt;&lt;P&gt;%let nobs = %sysfunc( attrn(&amp;amp;dsid,nobs) ); &lt;/P&gt;&lt;P&gt;%let rc = %sysfunc( close(&amp;amp;dsid) ); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if &amp;amp;nobs gt 0 %then %do. . . &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 18:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/80451#M17334</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2013-09-12T18:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to test for zero observations and still be in control</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/258577#M49836</link>
      <description>&lt;P&gt;This is a great topic,&amp;nbsp;if instead of logging or emailing like shown I wanted to add one record to the dataset with the string&lt;/P&gt;
&lt;P&gt;'No data found' or something similar what would be a good a process to do for this case?&amp;nbsp;&amp;nbsp;&amp;nbsp; I am sorry if this should be a new topic.&amp;nbsp; I like the thread but in my case I have a macro that processes 6-8 file types and is processing my full file system for metadata and in some cases there is no result and I wanted my master report to have a new tab per file type with an one liner saying "no data found" for any given type meeting the condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the macro for the ODS, what I am not sure how to do is if empty dataset found add the one liner inside the ods or as a seperate data step/proc SQL right before. TIA from a green horn.&amp;nbsp;&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS if the ODS call can do this all the better- but that for sure should be a new topic.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2016 23:53:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/258577#M49836</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2016-03-23T23:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to test for zero observations and still be in control</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/258659#M49871</link>
      <description>&lt;P&gt;I use something like this. &amp;nbsp;If the data is empty add one obs and check for a missing variable in COMPUTE AFTER; &amp;nbsp;MODIFY keeps from breaking the data when it HAS obs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: 24MAR2015 My example data has ONE obs but should have ZERO so the MODIFY is not adding an observations with all missing values. &amp;nbsp;The output statement in the first data step should be removed to model the exact scenario. &amp;nbsp;The PROC REPORT works the same either way no matter how the "one all missing obs data set is created".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This method has can be modified to function at the end of a breaking variable not just at end of report. &amp;nbsp;I have used this technique in BIMO listings where I want a message "No data for this study site: &amp;lt;siteid&amp;gt;" &amp;nbsp; the site records are created by merging&amp;nbsp;the listing data with a list (data set) of all sites.&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;data class;
   *output; to model the zero obs scenario;
   stop;
   set sashelp.class;
   run;
*Add one obs to class if it is empty;
data class;
   if eof then output;
   stop;
   modify class end=eof;
   run;
options missing=' ';
proc report data=class list missing;
   columns _all_;
   define name / order;
   compute after name;
      msg = 'No data for this report.';
      l = length(msg);
      if not missing(name) then l=0;
      line msg $varying. l;
      endcomp;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2444iBB52DF02A1507990/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 12:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/258659#M49871</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-03-24T12:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to test for zero observations and still be in control</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/258680#M49881</link>
      <description>&lt;P&gt;That dose produce the type result I want/need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will have to learn proc report, it is not in my arsenal at this time, or see if any options relate to the ODS.&amp;nbsp; I was talking about having each data set defined so I might use them with a ODS print like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* --- Generate Excel report ---;
ods Tagsets.ExcelXP 
    path = "&amp;amp;pname."
    file = "&amp;amp;outputfile."
	style = Irstyle_xl_sm_titles_grid
	options (
        Embedded_Titles='Yes'
		Embedded_Footnotes='Yes'
        print_footer='&amp;amp;amp;L&amp;amp;amp;A &amp;amp;amp;R(&amp;amp;amp;P of &amp;amp;amp;N)'
		zoom='100'
	 );


%macro excel_report(databasetype);
ods Tagsets.ExcelXP options 
(
    sheet_interval='proc'
	sheet_name="&amp;amp;databasetype."
	orientation = 'landscape'
	frozen_headers = '5'
	frozen_rowheaders = '2'
	row_repeat='4-5'
	column_repeat='1-2'
	Pages_FitWidth='1'
	Autofit_height='yes'
	Absolute_Column_Width='27.5,7.4,16,16,16,16,,8,8,8,8,8'
	Scale='90'
);

* --- print ---;
proc print data=d_&amp;amp;databasetype._w_match noobs label split='\';
title1 "Files found with data type: &amp;amp;databasetype.";
footnote2 "&amp;amp;tdate.";
footnote3 "file: &amp;amp;outputfile.";
footnote4 "program: &amp;amp;fname";
run;
%mend excel_report;

%excel_report(MDB);
%excel_report(DBF);
%excel_report(SAV);
%excel_report(XLS);
...
&lt;BR /&gt;ods tagsets.Excelxp close ;
...
where all these data sets exist...
/*proc print data= d_DBF_w_match;run;*/
/*proc print data= d_SAV_w_match;run;*/
/*proc print data= d_XLS_w_match;run;*/
...
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It seems like if I was reading your code and results correctly that no record was actually created with your method.&amp;nbsp; However I now have options.&amp;nbsp; output is the key not the road i travel...&amp;nbsp; Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2016 23:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/258680#M49881</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2016-03-23T23:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to test for zero observations and still be in control</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/258786#M49918</link>
      <description>&lt;P&gt;This one replaces the data set with one record and one var MSG. &amp;nbsp;If the data has records it is untouched just be sure to STOP before the SET.&lt;/P&gt;
&lt;P&gt;This works as long as your PROC PRINT does not have a VAR statement. &amp;nbsp;If it did you could create a macro variable flag in the CALL EXECUTE to change the VAR statement. &amp;nbsp;%if &amp;amp;noobs %then %do;,,,%end; %else %do; ,,, %end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2451i0606E9BF2763A6E5/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&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;data class;
   stop;
   set sashelp.class;
   run;
*Add one obs to class if it is empty;
%let databasetype=class;

data _null_;
   if eof then do;
      call execute("data &amp;amp;databasetype; msg='No data to report'; label msg='\'; run;");
      end;
   stop;
   set class end=eof;
   run;
options missing=' ';
proc print data=&amp;amp;databasetype noobs label split='\';
   title1 "Files found with data type: &amp;amp;databasetype.";
   run;
title;
footnote2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Mar 2016 12:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-for-zero-observations-and-still-be-in-control/m-p/258786#M49918</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-03-24T12:41:20Z</dc:date>
    </item>
  </channel>
</rss>

