<?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 do I read empty dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395437#M95375</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;_NULL_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;TEST &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;END&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=LAST;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;IF&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; LAST &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;THEN&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;CALL&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SYMPUT('TOTAL_RECORD'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,_N_) ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Above is the sample code to calculate the number of observation for dataset Test. If the dataset contains data, then it shouldnt be a problem. But if the Test data is empty, when I&amp;nbsp;read &amp;amp;Total_record it will prompt warning and stop the process.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference &lt;FONT face="Courier New"&gt;Total_record &lt;/FONT&gt;not resolved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My expectation is, eventhough its empty, i still need it to have 0 value when i call &amp;amp;&lt;FONT face="Courier New"&gt;Total_record. Please help.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;Thanks.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Sep 2017 09:09:24 GMT</pubDate>
    <dc:creator>Hhh111</dc:creator>
    <dc:date>2017-09-13T09:09:24Z</dc:date>
    <item>
      <title>How do I read empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395437#M95375</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;_NULL_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;TEST &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;END&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=LAST;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;IF&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; LAST &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;THEN&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;CALL&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SYMPUT('TOTAL_RECORD'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,_N_) ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Above is the sample code to calculate the number of observation for dataset Test. If the dataset contains data, then it shouldnt be a problem. But if the Test data is empty, when I&amp;nbsp;read &amp;amp;Total_record it will prompt warning and stop the process.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference &lt;FONT face="Courier New"&gt;Total_record &lt;/FONT&gt;not resolved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My expectation is, eventhough its empty, i still need it to have 0 value when i call &amp;amp;&lt;FONT face="Courier New"&gt;Total_record. Please help.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;Thanks.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 09:09:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395437#M95375</guid>
      <dc:creator>Hhh111</dc:creator>
      <dc:date>2017-09-13T09:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395440#M95377</link>
      <description>&lt;P&gt;Avoid coding all in uppercase, its really hard to read. &amp;nbsp;As for your problem you do not need to do anything, just a minor change to your code will get you the result - assume library is work and dataset is test:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vtable (where=(libname="WORK" and memname="TEST"));
  call symput('TOTAL_RECORD',nobs);
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2017 09:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395440#M95377</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-09-13T09:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395447#M95383</link>
      <description>&lt;P&gt;As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;has already shown, there are better ways to get the number of records in a dataset that don't require reading every record.&amp;nbsp; My favorite paper on counting records (and checking for empty datasets) is still:&amp;nbsp; &lt;A href="http://www2.sas.com/proceedings/sugi26/p095-26.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi26/p095-26.pdf&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, it's helpful to think through why moving your CALL SYMPUT to before the SET statement would achieve what you want.&amp;nbsp; The data step is a loop, which will stop when the SET statement tries to read a record but there is nothing to be read.&amp;nbsp; Knowing that, and that end= variable is given a value even before the SET statement executes the first time, you could do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  stop;
run;

data _null_;
  if last then call symputx('Total_Record',_N_-1);
  set test end=last;
run;

%put &amp;amp;Total_Record;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's ofen useful to put an IF LAST block before the SET statement, even though this doesn't always feel like the 'logical' location for the code, until you think through that the statement immediately before the SET statement is the last statement that will execute.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 10:01:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395447#M95383</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-09-13T10:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395665#M95472</link>
      <description>&lt;P&gt;There are a lot of ways to check empty dataset as discussed in previous post &lt;A href="https://communities.sas.com/t5/SAS-in-Health-Care-Related/Check-if-the-table-is-empty/td-p/6439" target="_blank"&gt;https://communities.sas.com/t5/SAS-in-Health-Care-Related/Check-if-the-table-is-empty/td-p/6439&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is one macro solution&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro emptycheck(ds=);
	%global TOTAL_RECORD;
	%LET dsid=%SYSFUNC(OPEN(&amp;amp;ds.));
	%LET TOTAL_RECORD=%SYSFUNC(ATTRN(&amp;amp;dsid.,NOBS));
	%LET rc=%SYSFUNC(CLOSE(&amp;amp;dsid.));
	%put dsid=&amp;amp;dsid. TOTAL_RECORD=&amp;amp;TOTAL_RECORD. rc=&amp;amp;rc.;
	%if &amp;amp;TOTAL_RECORD=0 %then %do; 
		%put This dataset (&amp;amp;ds.) is empty and has &amp;amp;TOTAL_RECORD. obs;
		
	%end;
	%else %do;
		%put This dataset (&amp;amp;ds.) is not empty and has &amp;amp;TOTAL_RECORD. obs;
	%end;
%mend emptycheck;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2017 17:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395665#M95472</guid>
      <dc:creator>MINX</dc:creator>
      <dc:date>2017-09-13T17:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395738#M95490</link>
      <description>&lt;P&gt;Hi hhh111&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your problem is that the CALL SYMPUTX&amp;nbsp;- statement never executes if the data set is empty, and the&amp;nbsp;macro variable Total_Record is not created. That's why it says that the apparent symbolic reference is not resolved. The simple solution is to use your code as is is, and initiate the macro variable &lt;U&gt;before&lt;/U&gt; the step, so it always exists whether the &lt;SPAN&gt;CALL SYMPUTX&lt;/SPAN&gt; executes or not:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let Total_Record = 0;&lt;BR /&gt;data _null_;&lt;BR /&gt; set test end=last;&lt;BR /&gt; if last then call symputx('Total_Record',_N_);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use your code on several datasets in the same sesson,&amp;nbsp;an empty data will not reset the value from the previous&amp;nbsp;check, but will inherit the number of observations. You can avoid that too by initiating the macro variable to 0 before each check.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 19:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395738#M95490</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2017-09-13T19:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395743#M95493</link>
      <description>&lt;P&gt;See example 4 of this paper (&lt;A href="http://www2.sas.com/proceedings/sugi24/Handson/p149-24.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi24/Handson/p149-24.pdf&lt;/A&gt;).&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 19:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395743#M95493</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2017-09-13T19:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395818#M95525</link>
      <description>&lt;P&gt;You simply need to call the symput function before the data step stops.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data TEST;
  stop;
run;

data _null_;
  call symputx('NOBS',NOBS);
  set SASHELP.CLASS(obs=1) nobs=NOBS;
run;
%put &amp;amp;=NOBS;

data _null_;
  call symputx('NOBS',NOBS);
  set TEST(obs=1) nobs=NOBS;
run;
%put &amp;amp;=NOBS;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NOBS=19&lt;BR /&gt;NOBS=0&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 00:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395818#M95525</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-09-14T00:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395838#M95535</link>
      <description>&lt;P&gt;Try this one.....&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql noprint;
  select count(&amp;lt;PRIMARY KEY&amp;gt;) into: total_records
  from &amp;lt;YOUR INPUT DATASET &amp;gt;;
quit;

%put Total observations: &amp;amp;Total_records.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 02:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-empty-dataset/m-p/395838#M95535</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2017-09-14T02:20:12Z</dc:date>
    </item>
  </channel>
</rss>

