<?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 how to check if a dataset is empty in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-check-if-a-dataset-is-empty/m-p/428024#M27562</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have seen a lot of message on how to check if a dataset is empty but many of the proposed codes generate errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my little contribution to the community.&lt;/P&gt;&lt;P&gt;I have test this code and it seems to works properly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note that my dataset named base is empty (no column, no observations) and &amp;amp;records gives zero.&lt;/P&gt;&lt;P&gt;You can replace the dataset by sashelp.class to test with a non zero dataset.&amp;nbsp; It works fine with both situation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can use the macro variable &amp;amp;records with a conditionnal statement to do what you want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_; /*data step to check for number of records in your dataset*/&lt;BR /&gt;%global records;&lt;BR /&gt;%let records=0;&lt;BR /&gt;set base end=last;&lt;BR /&gt;if last then call symput("Records",put(_n_,8.)); /*_n_ is observation number in sas dataset*/&lt;BR /&gt;run;&lt;BR /&gt;%put &amp;amp;records;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jan 2018 14:32:57 GMT</pubDate>
    <dc:creator>alepage</dc:creator>
    <dc:date>2018-01-16T14:32:57Z</dc:date>
    <item>
      <title>how to check if a dataset is empty</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-check-if-a-dataset-is-empty/m-p/428024#M27562</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have seen a lot of message on how to check if a dataset is empty but many of the proposed codes generate errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my little contribution to the community.&lt;/P&gt;&lt;P&gt;I have test this code and it seems to works properly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note that my dataset named base is empty (no column, no observations) and &amp;amp;records gives zero.&lt;/P&gt;&lt;P&gt;You can replace the dataset by sashelp.class to test with a non zero dataset.&amp;nbsp; It works fine with both situation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can use the macro variable &amp;amp;records with a conditionnal statement to do what you want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_; /*data step to check for number of records in your dataset*/&lt;BR /&gt;%global records;&lt;BR /&gt;%let records=0;&lt;BR /&gt;set base end=last;&lt;BR /&gt;if last then call symput("Records",put(_n_,8.)); /*_n_ is observation number in sas dataset*/&lt;BR /&gt;run;&lt;BR /&gt;%put &amp;amp;records;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 14:32:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-check-if-a-dataset-is-empty/m-p/428024#M27562</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2018-01-16T14:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if a dataset is empty</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-check-if-a-dataset-is-empty/m-p/428037#M27564</link>
      <description>&lt;P&gt;Nice, but for most (except DB libnames) datasets the observation count is already present in sashelp.vtables (or the SQL dictionary equivalent).&amp;nbsp; So if you really need a macro variable (and for most operations you wouldn't, only maybe fr create an output report):&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vtable (where=(libname="&amp;lt;yourlib&amp;gt;" and memname="&amp;lt;yourds&amp;gt;"));
  call symput("records",put(nobs,best.));
run;&lt;/PRE&gt;
&lt;P&gt;If I need a report though, simpler to do:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vtable (where=(libname="&amp;lt;yourlib&amp;gt;" and memname="&amp;lt;yourds&amp;gt;"));
  if nobs &amp;gt; 0 then call execute('%Do_Report');
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2018 14:48:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-check-if-a-dataset-is-empty/m-p/428037#M27564</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-16T14:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if a dataset is empty</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-check-if-a-dataset-is-empty/m-p/428349#M27597</link>
      <description>&lt;P&gt;if it is zero ,then table is empty .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsid=%sysfunc(open(sashelp.class));
%let nobs=%sysfunc(attrn(&amp;amp;dsid,nlobs));
%let dsid=%sysfunc(close(&amp;amp;dsid));

%put nobs= &amp;amp;nobs ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jan 2018 13:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-check-if-a-dataset-is-empty/m-p/428349#M27597</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-01-17T13:15:32Z</dc:date>
    </item>
  </channel>
</rss>

