<?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: get table size macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/get-table-size-macro/m-p/573565#M12531</link>
    <description>sorry I am new in sas programming.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I forgot to add in the line nobs = size;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;And I'm sorry... I didn't understand any of your solution.... where to add the %let statement and what is it for?&amp;nbsp; and also if I call symputx before set, how do I specify nobs = size?&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 15 Jul 2019 15:45:14 GMT</pubDate>
    <dc:creator>laiguanyu001</dc:creator>
    <dc:date>2019-07-15T15:45:14Z</dc:date>
    <item>
      <title>get table size macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-table-size-macro/m-p/573548#M12529</link>
      <description>&lt;P&gt;Hi, I found a macro that gets a table's size. I was wondering if there's a way to adjust it so it can output an empty table?&amp;nbsp;&lt;BR /&gt;%macro get_table_size(inset,macvar);&lt;BR /&gt;data _null_;&lt;BR /&gt;set &amp;amp;inset ;&lt;BR /&gt;call symput("&amp;amp;macvar",size);&lt;BR /&gt;stop;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here's how to use it:&lt;/P&gt;&lt;P&gt;%let count=;&lt;/P&gt;&lt;P&gt;%get_table_size(table, count);&lt;/P&gt;&lt;P&gt;%put &amp;amp;=count;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;right now for empty table, %put statement will return count =&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want it to return count = 0 because then I will expand this to:&lt;/P&gt;&lt;P&gt;if &amp;amp;count= 0 then do;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;message = 'table is empty';&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;how may I do this? Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 15:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-table-size-macro/m-p/573548#M12529</guid>
      <dc:creator>laiguanyu001</dc:creator>
      <dc:date>2019-07-15T15:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: get table size macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-table-size-macro/m-p/573555#M12530</link>
      <description>&lt;P&gt;What is the SIZE variable in your CALL SYMPUT statement?&amp;nbsp; (And why are you using the old CALL SYMPUT instead of CALL SYMPUTX?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can force the CALL SYMPUTX() statement to run even if the input dataset is empty by moving it to BEFORE the SET statement.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could just add a %LET to your macro.&lt;/P&gt;
&lt;P&gt;Or you could change the %LET before your macro call.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 15:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-table-size-macro/m-p/573555#M12530</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-15T15:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: get table size macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-table-size-macro/m-p/573565#M12531</link>
      <description>sorry I am new in sas programming.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I forgot to add in the line nobs = size;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;And I'm sorry... I didn't understand any of your solution.... where to add the %let statement and what is it for?&amp;nbsp; and also if I call symputx before set, how do I specify nobs = size?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 15 Jul 2019 15:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-table-size-macro/m-p/573565#M12531</guid>
      <dc:creator>laiguanyu001</dc:creator>
      <dc:date>2019-07-15T15:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: get table size macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-table-size-macro/m-p/573610#M12544</link>
      <description>&lt;P&gt;Most SAS data steps stop when they read past the end of the input. So if you are reading from an empty dataset then any statement in the data step that is after the SET statement will never execute since the step stops as soon as it tries to read a non-existing observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So it sounds like you want to know if you can use the NOBS= option of the SET statement to populate a macro variable that you can later test.&amp;nbsp; Since SAS will set the NOBS= variable's value while building the data step you can reference its value before the SET statement even executes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro get_table_size(inset,macvar);
%if not %symexist(&amp;amp;macvar) %then %global &amp;amp;macvar;
data _null_;
  call symputx("&amp;amp;macvar",size);
  stop;
  set &amp;amp;inset nobs=size;
run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Adding the test will make sure that the caller can reference the macro variable, even if they did not create it before calling.&lt;/P&gt;
&lt;P&gt;Use the newer (better?) CALL SYMPUTX() function will make sure that the value does not have leading spaces or get converted to scientific notation when larger than 999,999,999,999.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 17:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-table-size-macro/m-p/573610#M12544</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-15T17:38:21Z</dc:date>
    </item>
  </channel>
</rss>

