<?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 identify an empty dataset? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27976#M6458</link>
    <description>&lt;P&gt;&lt;EM&gt;Editor's note: This topic is&amp;nbsp;&lt;STRONG&gt;very&lt;/STRONG&gt; popular. &amp;nbsp;data_null__ ,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13599"&gt;@Bill﻿&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13636"&gt;@sbb﻿&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;&amp;nbsp;and others have contributed great ideas. &amp;nbsp;We've consolidated those here with a little more detail to help future readers.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For this kind of problem the question is not&lt;BR /&gt;&amp;nbsp;- how many obs?&lt;BR /&gt; but&lt;BR /&gt;&amp;nbsp;- are there &lt;EM&gt;zero&lt;/EM&gt; obs?&lt;BR /&gt; &lt;BR /&gt; You don't have to count anything -- just check for imediate EOF.&lt;BR /&gt; &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Init check flag */
%let dsempty=0;

/* destination for XLSX file, if generated */
filename outfile "%sysfunc(getoption(work))/class.xlsx";

/* create empty test data set by removing all records */
data class;
 set sashelp.class;
run;
data class;
 modify class;
 remove;
run;

/* Check for empty data */
data _null_;
  if eof then
    do;
     call symput('dsempty',1);
     put 'NOTE: EOF - no records in data!';
    end;
  stop;
  set class end=eof;
run;

%macro Export;
  %if &amp;amp;dsempty. %then
    %do;
      %put WARNING: Export step skipped - no output records.;
    %end;
  %else
    %do;
      /*if not empty then execute the export proc*/
      proc export data=class dbms=xlsx 
        file=outfile replace;
      run;
    %end;
%mend Export;

%Export;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 07 Jul 2016 15:03:21 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2016-07-07T15:03:21Z</dc:date>
    <item>
      <title>How to identify an empty dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27970#M6452</link>
      <description>Hi Everyone,&lt;BR /&gt;
&lt;BR /&gt;
I am working on creating an Excel report using proc export. However, I don't want to create a report if the dataset is empty. Could anyone please suggest me a way how to check to see if a dataset is empty or not?&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance for your help.&lt;BR /&gt;
Lani</description>
      <pubDate>Thu, 27 May 2010 03:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27970#M6452</guid>
      <dc:creator>Lani</dc:creator>
      <dc:date>2010-05-27T03:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify an empty dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27971#M6453</link>
      <description>You could use the ATTRN function, which will give tje number of observations in a data set.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Thu, 27 May 2010 09:46:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27971#M6453</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2010-05-27T09:46:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify an empty dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27972#M6454</link>
      <description>I don't understand exactly about empty dataset .&lt;BR /&gt;
Is that to mean no observations or all of variables in the dataset have missing value.&lt;BR /&gt;
The following code can print the number of observations in the log .&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  set yourdataset nobs=number;&lt;BR /&gt;
  put number= ;&lt;BR /&gt;
  stop;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Also you can use proc sql to get the number of observations.&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Thu, 27 May 2010 13:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27972#M6454</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-05-27T13:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify an empty dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27973#M6455</link>
      <description>Untested ...&lt;BR /&gt;
&lt;BR /&gt;
data _null_;   /*data step to check for number of records in file to be exported/*                                                                                                                           &lt;BR /&gt;
set exportfile end=last;                                                                                                                &lt;BR /&gt;
if last then call symput("Records",_n_);   /*_n_ is observation number in sas dataset*/                                                                                                  &lt;BR /&gt;
run;                                                                                                                                    &lt;BR /&gt;
                                                                                                                                        &lt;BR /&gt;
%macro Export;                                                                                                                          &lt;BR /&gt;
%if &amp;amp;Nobs &amp;gt; 0 %then %do;    /*if records &amp;gt; 0 then execute the export proc*/                                                                                                               &lt;BR /&gt;
proc export ....                                                                                                                        &lt;BR /&gt;
run;                                                                                                                  %end;                  &lt;BR /&gt;
%mend Export;                                                                                                                           &lt;BR /&gt;
%Export;</description>
      <pubDate>Thu, 27 May 2010 19:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27973#M6455</guid>
      <dc:creator>Bill</dc:creator>
      <dc:date>2010-05-27T19:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify an empty dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27974#M6456</link>
      <description>The IF test must occur BEFORE the SET to work with a zero-observations condition.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 27 May 2010 22:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27974#M6456</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-05-27T22:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify an empty dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27975#M6457</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
The ATTRN function will help.  If that looks difficult proc sql can also be used. &lt;BR /&gt;
&lt;BR /&gt;
 proc sql noprint;&lt;BR /&gt;
    select count(*) into :obs_count from dataset1;&lt;BR /&gt;
 quit;&lt;BR /&gt;
&lt;BR /&gt;
%if (&amp;amp;obs_count ne) %then %do;&lt;BR /&gt;
proc export ........&lt;BR /&gt;
..........&lt;BR /&gt;
&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
Sandhya.</description>
      <pubDate>Tue, 01 Jun 2010 15:16:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27975#M6457</guid>
      <dc:creator>Sandhya</dc:creator>
      <dc:date>2010-06-01T15:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify an empty dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27976#M6458</link>
      <description>&lt;P&gt;&lt;EM&gt;Editor's note: This topic is&amp;nbsp;&lt;STRONG&gt;very&lt;/STRONG&gt; popular. &amp;nbsp;data_null__ ,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13599"&gt;@Bill﻿&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13636"&gt;@sbb﻿&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;&amp;nbsp;and others have contributed great ideas. &amp;nbsp;We've consolidated those here with a little more detail to help future readers.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For this kind of problem the question is not&lt;BR /&gt;&amp;nbsp;- how many obs?&lt;BR /&gt; but&lt;BR /&gt;&amp;nbsp;- are there &lt;EM&gt;zero&lt;/EM&gt; obs?&lt;BR /&gt; &lt;BR /&gt; You don't have to count anything -- just check for imediate EOF.&lt;BR /&gt; &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Init check flag */
%let dsempty=0;

/* destination for XLSX file, if generated */
filename outfile "%sysfunc(getoption(work))/class.xlsx";

/* create empty test data set by removing all records */
data class;
 set sashelp.class;
run;
data class;
 modify class;
 remove;
run;

/* Check for empty data */
data _null_;
  if eof then
    do;
     call symput('dsempty',1);
     put 'NOTE: EOF - no records in data!';
    end;
  stop;
  set class end=eof;
run;

%macro Export;
  %if &amp;amp;dsempty. %then
    %do;
      %put WARNING: Export step skipped - no output records.;
    %end;
  %else
    %do;
      /*if not empty then execute the export proc*/
      proc export data=class dbms=xlsx 
        file=outfile replace;
      run;
    %end;
%mend Export;

%Export;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jul 2016 15:03:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/27976#M6458</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-07-07T15:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify an empty dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/342242#M63308</link>
      <description>This is what I've been looking for, simple and very useful.</description>
      <pubDate>Sat, 18 Mar 2017 15:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-identify-an-empty-dataset/m-p/342242#M63308</guid>
      <dc:creator>Schoolmaster</dc:creator>
      <dc:date>2017-03-18T15:20:46Z</dc:date>
    </item>
  </channel>
</rss>

