<?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: Output with no records in Developers</title>
    <link>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61757#M3140</link>
    <description>Hi:&lt;BR /&gt;
  I agree with Vince. This is more of a BASE SAS and SAS MACRO question. There is no "automatic" global macro variable that tell whether no records were found in a dataset. However, you could use a technique similar to the one shown in the this previous forum posting:&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=6659ᨃ" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=6659ᨃ&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
  Although the initial question was about IF statements, there is an example of finding out the number of observations in a dataset and issuing an error message if no observations are found. &lt;BR /&gt;
 &lt;BR /&gt;
  Other relevant posts are these:&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=8828≼" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=8828≼&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=33691莛" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=33691莛&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=16219㽛" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=16219㽛&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=8249‹" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=8249‹&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Most of these previous postings show the use of "dictionary" tables to determine the number of observations in a dataset. Several previous forum postings have discussed the use of DICTIONARY.TABLES and other types of DICTIONARY files in order to access information about SAS datasets. With PROC SQL, you can use the INTO clause in order to create macro variables from the results of a particular query. Some of the postings are:&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=14535㣇" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=14535㣇&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=9171⏓" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=9171⏓&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=11252⯴" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=11252⯴&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Here are some user group papers that outline what the "dictionary" tables do:&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi30/070-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/070-30.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi29/237-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/237-29.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www.codecraftersinc.com/pdf/DictionaryTablesRefCard.pdf" target="_blank"&gt;http://www.codecraftersinc.com/pdf/DictionaryTablesRefCard.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www.lexjansen.com/pharmasug/2006/tutorials/tu03.pdf" target="_blank"&gt;http://www.lexjansen.com/pharmasug/2006/tutorials/tu03.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www.qsl.net/kd6ttl/sas/sqlutilov.pdf" target="_blank"&gt;http://www.qsl.net/kd6ttl/sas/sqlutilov.pdf&lt;/A&gt;&lt;BR /&gt;
   &lt;BR /&gt;
Before you roll the necessary logic into a stored process, however, I recommend that you understand how the macro variables will work outside of a stored process, by creating some test programs, in order to aid in debugging your changed program (before you modify your stored process code).&lt;BR /&gt;
          &lt;BR /&gt;
cynthia</description>
    <pubDate>Mon, 09 Aug 2010 15:35:45 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2010-08-09T15:35:45Z</dc:date>
    <item>
      <title>Output with no records</title>
      <link>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61755#M3138</link>
      <description>hi,&lt;BR /&gt;
&lt;BR /&gt;
can you please tell me which global macro variable i have to use if no records are found in dataset i,e if i run stored process and it didn't fetch any data,then in output it has to display as&lt;BR /&gt;
 "NO OBSERVATIONS IN OUTPUT DATASET".&lt;BR /&gt;
If it has observations then it has to perform its job normally.&lt;BR /&gt;
&lt;BR /&gt;
Thanks &amp;amp; Regards,&lt;BR /&gt;
SASA</description>
      <pubDate>Mon, 09 Aug 2010 08:56:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61755#M3138</guid>
      <dc:creator>MaheshPeesari</dc:creator>
      <dc:date>2010-08-09T08:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: Output with no records</title>
      <link>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61756#M3139</link>
      <description>This is more of a Base SAS question.  If you post a small sample of the code that results in no observations being fetched, somebody might be able to give you some advice.&lt;BR /&gt;
&lt;BR /&gt;
Vince DelGobbo&lt;BR /&gt;
SAS R&amp;amp;D</description>
      <pubDate>Mon, 09 Aug 2010 13:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61756#M3139</guid>
      <dc:creator>Vince_SAS</dc:creator>
      <dc:date>2010-08-09T13:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: Output with no records</title>
      <link>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61757#M3140</link>
      <description>Hi:&lt;BR /&gt;
  I agree with Vince. This is more of a BASE SAS and SAS MACRO question. There is no "automatic" global macro variable that tell whether no records were found in a dataset. However, you could use a technique similar to the one shown in the this previous forum posting:&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=6659ᨃ" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=6659ᨃ&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
  Although the initial question was about IF statements, there is an example of finding out the number of observations in a dataset and issuing an error message if no observations are found. &lt;BR /&gt;
 &lt;BR /&gt;
  Other relevant posts are these:&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=8828≼" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=8828≼&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=33691莛" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=33691莛&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=16219㽛" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=16219㽛&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=8249‹" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=8249‹&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Most of these previous postings show the use of "dictionary" tables to determine the number of observations in a dataset. Several previous forum postings have discussed the use of DICTIONARY.TABLES and other types of DICTIONARY files in order to access information about SAS datasets. With PROC SQL, you can use the INTO clause in order to create macro variables from the results of a particular query. Some of the postings are:&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=14535㣇" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=14535㣇&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=9171⏓" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=9171⏓&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=11252⯴" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=11252⯴&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Here are some user group papers that outline what the "dictionary" tables do:&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi30/070-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/070-30.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi29/237-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/237-29.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www.codecraftersinc.com/pdf/DictionaryTablesRefCard.pdf" target="_blank"&gt;http://www.codecraftersinc.com/pdf/DictionaryTablesRefCard.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www.lexjansen.com/pharmasug/2006/tutorials/tu03.pdf" target="_blank"&gt;http://www.lexjansen.com/pharmasug/2006/tutorials/tu03.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www.qsl.net/kd6ttl/sas/sqlutilov.pdf" target="_blank"&gt;http://www.qsl.net/kd6ttl/sas/sqlutilov.pdf&lt;/A&gt;&lt;BR /&gt;
   &lt;BR /&gt;
Before you roll the necessary logic into a stored process, however, I recommend that you understand how the macro variables will work outside of a stored process, by creating some test programs, in order to aid in debugging your changed program (before you modify your stored process code).&lt;BR /&gt;
          &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 09 Aug 2010 15:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61757#M3140</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-08-09T15:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Output with no records</title>
      <link>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61758#M3141</link>
      <description>Perhaps this example will be helpful.  Comment the REMOVE statement to toggle obs vs no obs.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data class;&lt;BR /&gt;
   set sashelp.class;&lt;BR /&gt;
   run;&lt;BR /&gt;
data class;&lt;BR /&gt;
   modify class;&lt;BR /&gt;
   remove;&lt;BR /&gt;
   run;&lt;BR /&gt;
ods pdf file='noreportexample.pdf';&lt;BR /&gt;
title 'Title for report';&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   attrib name length=$50 label='00'x;&lt;BR /&gt;
   if eof then do;&lt;BR /&gt;
      file print ods;&lt;BR /&gt;
      put 'No Obs to report';&lt;BR /&gt;
      end;&lt;BR /&gt;
   stop;&lt;BR /&gt;
   set class(keep=name) end=eof;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc report data=class nowd list;&lt;BR /&gt;
   run;&lt;BR /&gt;
ods pdf close;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 09 Aug 2010 18:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61758#M3141</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-08-09T18:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Output with no records</title>
      <link>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61759#M3142</link>
      <description>Hi:&lt;BR /&gt;
  The DATA _NULL_ approach with the PUT statement might not work when a program is turned into a stored process, because %STPBEGIN typically "grabs" _webout and sometimes the PUT statement doesn't work in a stored process -- at least that was the recommendation in SAS 9.1.3 -- to avoid PUTs in DATA _NULL_ programs. &lt;BR /&gt;
&lt;BR /&gt;
  Typically, the way to get around this would be to put one obs in an "error" dataset -- where the obs was the error message that you want to display and then do a PROC PRINT or PROC REPORT on the error dataset. Also, if you used PROC REPORT to print the "error" message dataset, you would not need '00'x as the column header because REPORT has the NOHEADER option to suppress all headers.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 09 Aug 2010 19:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61759#M3142</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-08-09T19:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: Output with no records</title>
      <link>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61760#M3143</link>
      <description>My ignorance of stored processes is vast.  &lt;BR /&gt;
&lt;BR /&gt;
Do you think this, same but different, would work in a stored process?&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data class;&lt;BR /&gt;
   set sashelp.class;&lt;BR /&gt;
   run;&lt;BR /&gt;
data class;&lt;BR /&gt;
   modify class;&lt;BR /&gt;
   remove;&lt;BR /&gt;
   run;&lt;BR /&gt;
ods pdf file='noreportexample.pdf';&lt;BR /&gt;
title 'Title for report';&lt;BR /&gt;
data noreport;&lt;BR /&gt;
   if eof then do;&lt;BR /&gt;
      message = 'No Obs to report';&lt;BR /&gt;
      output;&lt;BR /&gt;
      call execute('proc report data=noreport nowd noheader; run;');&lt;BR /&gt;
      end;&lt;BR /&gt;
   stop;&lt;BR /&gt;
   set class(drop=_all_) end=eof;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc report data=class nowd list;&lt;BR /&gt;
   run;&lt;BR /&gt;
ods pdf close;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 09 Aug 2010 20:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61760#M3143</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-08-09T20:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Output with no records</title>
      <link>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61761#M3144</link>
      <description>Hi:&lt;BR /&gt;
  I don't know. I expect that it would work, if the timing of the  CALL EXECUTE placed the code with PROC REPORT -after- the DATA step, but before the %STPEND; was executed.&lt;BR /&gt;
 &lt;BR /&gt;
  I would probably opt for a very straightforward macro approach instead of tempting fate with CALL EXECUTE. Either using ATTRN or SELECT..INTO to get the number of obs returned by a process or query into a macro variable and then using %IF macro logic to conditionally execute the PROC REPORT with the error message or execute the other report if there are obs.&lt;BR /&gt;
&lt;BR /&gt;
  But I am very conservative in my approach to stored processes. Especially since I frequently refer to the stored process input parameters (chosen by the people who ran the stored process) in the error message. And, my rule of thumb with CALL EXECUTE is to only execute macro calls -- not send whole steps of program code within one quoted string -- because I like to let the code expansion and resolution happen in the macro word scanner.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 09 Aug 2010 22:06:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61761#M3144</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-08-09T22:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Output with no records</title>
      <link>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61762#M3145</link>
      <description>Thanks All  &lt;BR /&gt;
&lt;BR /&gt;
For u r suggestions.</description>
      <pubDate>Tue, 10 Aug 2010 13:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61762#M3145</guid>
      <dc:creator>MaheshPeesari</dc:creator>
      <dc:date>2010-08-10T13:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: Output with no records</title>
      <link>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61763#M3146</link>
      <description>I took data _null_'s first sample code and converted it into a stored process.  I tested the code on a stored process server running SAS®9.2 creating HTML, RTF or PDF.  It also works with streaming or package output.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data class;&lt;BR /&gt;
set sashelp.class;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data class;&lt;BR /&gt;
modify class;&lt;BR /&gt;
remove;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
if (eof) then do;&lt;BR /&gt;
  call symput('_ODSOPTIONS', "text='No Obs to report'");&lt;BR /&gt;
end;&lt;BR /&gt;
stop;&lt;BR /&gt;
set class(keep=name) end=eof;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%STPBEGIN;&lt;BR /&gt;
title 'Title for report';&lt;BR /&gt;
proc report data=class nowd list; run; quit;&lt;BR /&gt;
%STPEND;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Vince DelGobbo&lt;BR /&gt;
SAS R&amp;amp;D</description>
      <pubDate>Tue, 10 Aug 2010 13:28:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61763#M3146</guid>
      <dc:creator>Vince_SAS</dc:creator>
      <dc:date>2010-08-10T13:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: Output with no records</title>
      <link>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61764#M3147</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Thanks to everyone,For all your valuable inputs.&lt;BR /&gt;
&lt;BR /&gt;
I am using the below code to generate a message if no records in the final dataset.Thanks Once again for your valuable inputs.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data class;&lt;BR /&gt;
set sashelp.class;&lt;BR /&gt;
stop;&lt;BR /&gt;
run;  &lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
if 0 then set class nobs=nobs;&lt;BR /&gt;
call symput('datasetObs',compress(put(nobs,8.)));&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
%macro try;&lt;BR /&gt;
%put &amp;amp;datasetObs;&lt;BR /&gt;
%if &amp;amp;datasetObs = 0 %then %do;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
file _webout;&lt;BR /&gt;
put '&amp;lt;H1&amp;gt;NO RECORDS FETCHED FOR VALUES PASSED&amp;lt;/H1&amp;gt;';&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do; &lt;BR /&gt;
proc print data=class;    &lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend try;&lt;BR /&gt;
&lt;BR /&gt;
options mprint mlogic symbolgen;&lt;BR /&gt;
%try;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Thanks a lot...</description>
      <pubDate>Thu, 12 Aug 2010 06:28:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Output-with-no-records/m-p/61764#M3147</guid>
      <dc:creator>MaheshPeesari</dc:creator>
      <dc:date>2010-08-12T06:28:23Z</dc:date>
    </item>
  </channel>
</rss>

