<?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: print if data set is null in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492038#M129242</link>
    <description>&lt;P&gt;You have to either create a macro named %NOBS, or (hint hint hint) find it on the SAS website or elsewhere on the Internet, and then include it (or %include it) in your program before you call it.&lt;/P&gt;</description>
    <pubDate>Mon, 03 Sep 2018 12:19:52 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-09-03T12:19:52Z</dc:date>
    <item>
      <title>print if data set is null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492030#M129236</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I want that SAS will print a message if the data set is null&lt;/P&gt;&lt;P&gt;What is wrong with this code that I get error&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data   use_this_if_no_obs;
  msg = 'No Data';
run;

 data tbl_null;
  if 0;
run;
%let ds = %sysfunc(ifc(%nobs(iDs=tbl_null) eq 0, 
                 use_this_if_no_obs, 
                 tbl_null));
proc print data=&amp;amp;ds;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Sep 2018 11:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492030#M129236</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-09-03T11:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: print if data set is null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492032#M129237</link>
      <description>&lt;P&gt;What error do you get? Show us the SASLOG.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Sep 2018 12:05:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492032#M129237</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-09-03T12:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: print if data set is null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492034#M129239</link>
      <description>&lt;P&gt;WARNING: Apparent invocation of macro NOBS not resolved.&lt;BR /&gt;WARNING: Apparent invocation of macro NOBS not resolved.&lt;BR /&gt;ERROR: Required operator not found in expression: %nobs(iDs=tbl_null) eq 0&lt;BR /&gt;ERROR: Argument 1 to function IFC referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.&lt;BR /&gt;ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC&lt;BR /&gt;or %QSYSFUNC function reference is terminated.&lt;BR /&gt;21052 %let ds = %sysfunc(ifc(%nobs(iDs=tbl_null) eq 0,&lt;BR /&gt;21053 use_this_if_no_obs,&lt;BR /&gt;21054 tbl_null));&lt;BR /&gt;21055 proc print data=&amp;amp;ds;&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;ERROR 22-322: Expecting a name.&lt;BR /&gt;21056 run;&lt;BR /&gt;ERROR: File WORK.NAME.DATA does not exist.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Sep 2018 12:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492034#M129239</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-09-03T12:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: print if data set is null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492035#M129240</link>
      <description>&lt;P&gt;%nobs is no standard macro:&lt;/P&gt;
&lt;PRE&gt;35         %let ds = %sysfunc(ifc(%nobs(iDs=tbl_null) eq 0,
WARNING: Apparent invocation of macro NOBS not resolved.
36                          use_this_if_no_obs,
37                          tbl_null));
WARNING: Apparent invocation of macro NOBS not resolved.
&lt;/PRE&gt;
&lt;P&gt;To use it, you need to define it.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Sep 2018 12:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492035#M129240</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-03T12:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: print if data set is null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492037#M129241</link>
      <description>&lt;P&gt;How can I do it please?&lt;/P&gt;&lt;P&gt;Should I add one more %let statement?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Sep 2018 12:14:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492037#M129241</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-09-03T12:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: print if data set is null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492038#M129242</link>
      <description>&lt;P&gt;You have to either create a macro named %NOBS, or (hint hint hint) find it on the SAS website or elsewhere on the Internet, and then include it (or %include it) in your program before you call it.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Sep 2018 12:19:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492038#M129242</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-09-03T12:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: print if data set is null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492039#M129243</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How can I do it please?&lt;/P&gt;
&lt;P&gt;Should I add one more %let statement?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No. You simply program the logic yourself, using standard objects provided by SAS, in this case dictionary.tables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data use_this_if_no_obs;
msg = 'No Data';
run;

data tbl_null;
if 0;
run;

proc sql noprint;
select
  case
    when nobs = 0
    then 'use_this_if_no_obs'
    else memname
  end as ds into :ds
from dictionary.tables
where libname = 'WORK' and memname = 'TBL_NULL';
quit;

proc print data=&amp;amp;ds;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you get the code for the macro and include it either in the global autocall library of your SAS installation, or in all programs where you use it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Sep 2018 12:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492039#M129243</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-03T12:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: print if data set is null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492040#M129244</link>
      <description>&lt;PRE&gt;data  use_this_if_no_obs;
  msg='No Data';
run;

data _null_;
  set sashelp.vtable (where=(libname="WORK" and memname="ABC"));
  if nobs=0 then call execute('proc print data=use_this_if_no_obs; run;');
  else call execute('proc print data=abc; run;');
run;&lt;/PRE&gt;
&lt;P&gt;This will print use_this_if_no_obs is there are no observations in WORK.ABC.&amp;nbsp; Otherwise it will print WORK.ABC.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Sep 2018 12:29:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492040#M129244</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-03T12:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: print if data set is null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492042#M129245</link>
      <description>&lt;P&gt;Perfect!&lt;/P&gt;&lt;P&gt;How can I see it in Results window and not in log window?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Sep 2018 12:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492042#M129245</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-09-03T12:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: print if data set is null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492045#M129248</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Perfect!&lt;/P&gt;
&lt;P&gt;How can I see it in Results window and not in log window?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Look at your output window. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;'s code has proc print in the call execute, so it will create output (unless you have no ODS destination open).&lt;/P&gt;
&lt;P&gt;His code applied to your example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data use_this_if_no_obs;
msg = 'No Data';
run;

data tbl_null;
if 0;
run;

data _null_;
  set sashelp.vtable (where=(libname="WORK" and memname="TBL_NULL"));
  if nobs=0 then call execute('proc print data=use_this_if_no_obs; run;');
  else call execute('proc print data=abc; run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;gives this result:&lt;/P&gt;
&lt;PRE&gt;Obs      msg

 1     No Data
&lt;/PRE&gt;
&lt;P&gt;when list output is active in EG.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Sep 2018 12:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492045#M129248</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-03T12:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: print if data set is null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492046#M129249</link>
      <description>&lt;P&gt;I run the following code and unable to open the excel file.&lt;/P&gt;&lt;P&gt;I get an error in excel "unable to read the file"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;why???&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods path work.temptemp(update) sasuser.templat(update) 
sashelp.tmplmst(read);
ods path show; 
ods tagsets.excelxp file="/my personal computer address/w.xls" 
            style=htmlblue
          OPTIONS( embedded_titles='yes'
				SHEET_NAME="Joe"  
					absolute_column_width="17,20,7,9,9,9,11,13,11,11,11"
					sheet_interval="NONE"  );

data use_this_if_no_obs;
msg = 'No Data';
run;
data tbl_null;
if 0;
run;
data _null_;
  set tbl_null;
  if nobs=0 then call execute('proc print data=use_this_if_no_obs; run;');
  else call execute('proc print data=abc; run;');
run;

					ods tagsets.excelxp close;
ods _all_ close; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Sep 2018 12:57:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492046#M129249</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-09-03T12:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: print if data set is null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492050#M129251</link>
      <description>&lt;P&gt;You are trying to lie to Excel. The output from tagsets.excelpxp is not a xls, it's XML, so name your file accordingly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods tagsets.excelxp file="/my personal computer address/w.xml" &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Newer versions of Excel complain if the filename extension doesn't fit with the contents.&lt;/P&gt;
&lt;P&gt;The resulting file is readable with a simple text editor (notepad++ or similar) for control. You may have to open it manually from Excel, unless you associate .xml files with Excel in the Windows Explorer.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Sep 2018 13:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492050#M129251</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-03T13:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: print if data set is null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492074#M129259</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp; If you going to use that type of a program then you might just skip accessing the metadata and instead just reference the dataset itself.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  if eof then call execute('proc print data=use_this_if_no_obs; run;');
  else call execute('proc print data=abc; run;');
  stop;
  set WORK.ABC end=eof;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Although I think both methods will fail if WORK.ABC does not exist.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Sep 2018 15:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-if-data-set-is-null/m-p/492074#M129259</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-09-03T15:48:44Z</dc:date>
    </item>
  </channel>
</rss>

