<?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: How to get count of total records in a table in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6237#M1977</link>
    <description>Mohamed,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your reply!  That worked for what I wanted to know about my dataset.</description>
    <pubDate>Wed, 09 Jan 2008 16:50:27 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-01-09T16:50:27Z</dc:date>
    <item>
      <title>How to get count of total records in a table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6234#M1974</link>
      <description>Is there a simple way to get a count of the total number of records in a table, perhaps when using Proc SQL?&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance....looking forward to your replies!</description>
      <pubDate>Wed, 09 Jan 2008 14:17:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6234#M1974</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-09T14:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of total records in a table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6235#M1975</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt; &lt;BR /&gt; You can use the function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select count(*) as countrec from tablename;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;within your proc sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If the table is a SAS dataset, it has its size in the header and is accessible with the NOBS= option:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro get_table_size(inset,macvar);
 data _null_;
  set &amp;amp;inset NOBS=size;
  call symput("&amp;amp;macvar",size);
 stop;
 run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;This method takes O(k) time (that is constant time) and &lt;STRONG&gt;doesn't&lt;/STRONG&gt; require scanning through the table, O(n), to count the records. &amp;nbsp;Use it like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let reccount=;
%get_table_size(sashelp.cars,reccount);
%put &amp;amp;=reccount;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Feb 2017 14:06:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6235#M1975</guid>
      <dc:creator>MohamedS</dc:creator>
      <dc:date>2017-02-07T14:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of total records in a table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6236#M1976</link>
      <description>If the table is a SAS dataset, it has its size in the header and is accessible with the NOBS= option:&lt;BR /&gt;
&lt;BR /&gt;
%macro get_table_size(inset,macvar);&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  set &amp;amp;inset NOBS=size;&lt;BR /&gt;
  call symput("&amp;amp;macvar",size);&lt;BR /&gt;
  stop;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
This method takes O(k) time (that is constant time) and doesn't require scanning through the table, O(n), to count the records.&lt;BR /&gt;
&lt;BR /&gt;
To make the macro more robust, you would want to add a conditional wrapper:&lt;BR /&gt;
&lt;BR /&gt;
%if %sysfunc(exist(&amp;amp;inset)) %then %do;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
and then have some appropriate %else %do; for when the &amp;amp;inset doesn't "exist".&lt;BR /&gt;
&lt;BR /&gt;
I'm not sure if there is a generic way to distinguish a permanent SAS dataset from a database table.  I don't know if NOBS= will work for a database (Oracle, DB2, Sybase, Access, SQL Server, MySQL, etc. ).

Message was edited by: Chuck</description>
      <pubDate>Wed, 09 Jan 2008 15:24:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6236#M1976</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-09T15:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of total records in a table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6237#M1977</link>
      <description>Mohamed,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your reply!  That worked for what I wanted to know about my dataset.</description>
      <pubDate>Wed, 09 Jan 2008 16:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6237#M1977</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-09T16:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of total records in a table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6238#M1978</link>
      <description>Chuck,&lt;BR /&gt;
&lt;BR /&gt;
Interesting.... and thank you for the information.  I'll put that to good use as time progresses.</description>
      <pubDate>Wed, 09 Jan 2008 16:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6238#M1978</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-09T16:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of total records in a table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6239#M1979</link>
      <description>in proc sql, you could also go against a table's metadata in dictionary.tables to get the nobs in a data set:&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select nobs&lt;BR /&gt;
from dictionary.tables&lt;BR /&gt;
where libname eq 'SASHELP'&lt;BR /&gt;
and memname eq 'ZIPCODE';&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
this approach avoids actually reading the data set. if you're looking at a very large table, this can save lots of time; if you're accessing a remote library, it should also save time. this only appears to work for sas data sets and not for databases (sql, mysql, oracle, etc).&lt;BR /&gt;
&lt;BR /&gt;
i've also been unsuccessful with my attempts to access the view sashelp.vtable:&lt;BR /&gt;
data _null_;&lt;BR /&gt;
set sashelp.vtable;&lt;BR /&gt;
where libname eq 'SASHELP'&lt;BR /&gt;
and memname eq 'ZIPCODE';&lt;BR /&gt;
put nobs;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 09 Jan 2008 18:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6239#M1979</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-09T18:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of total records in a table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6240#M1980</link>
      <description>And thank you also, Richard.  So many ways to do the same thing!</description>
      <pubDate>Thu, 10 Jan 2008 20:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6240#M1980</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-10T20:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of total records in a table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6241#M1981</link>
      <description>I have no knowledge of macros, so I would like to know how to use the &lt;B&gt;get_table_size&lt;/B&gt; macro.&lt;BR /&gt;
&lt;BR /&gt;
If I have a data step:&lt;BR /&gt;
&lt;BR /&gt;
data new_table;&lt;BR /&gt;
set old_table;&lt;BR /&gt;
&lt;BR /&gt;
&lt;SOME code=""&gt;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
is it possible to call the macro in the same data step and assign the new_table number of rows to a variable nRows.&lt;BR /&gt;
&lt;BR /&gt;
I would like to see the macro call: &lt;BR /&gt;
&lt;BR /&gt;
nRows=%get_table_size( ?, ? );        /* Something like that? */&lt;/SOME&gt;</description>
      <pubDate>Tue, 24 Mar 2009 08:21:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6241#M1981</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-24T08:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of total records in a table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6242#M1982</link>
      <description>Since this is an EG forum, I'll mention that in EG you can right-click on a table and see the number of rows under Properties in the General pane. If it's a DMBS table and not a SAS data set, by default this will say unknown. You can change that under Tools \ Options \ Data General then check "Always obtain the total record count for DBMS tables". There could be performance issues with this, FYI, which is why it's not checked by default.</description>
      <pubDate>Wed, 25 Mar 2009 12:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6242#M1982</guid>
      <dc:creator>RichardH_sas</dc:creator>
      <dc:date>2009-03-25T12:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of total records in a table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6243#M1983</link>
      <description>Chuck,&lt;BR /&gt;
on a more basic level, what does the "&amp;amp;macvar" stand for? is this the name of the new variable you are creating which contains the total # of records?&lt;BR /&gt;
&lt;BR /&gt;
thanks, &lt;BR /&gt;
abc</description>
      <pubDate>Thu, 14 May 2009 20:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6243#M1983</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-14T20:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of total records in a table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6244#M1984</link>
      <description>for sas information about a table in a dbms, see corresponding rows in sashelp.vmember and sashelp.vviews.&lt;BR /&gt;
However, each dbms has its database information files equivalent to dictionary.tables. these probably could advise number of rows and columns (last time stats were collected). these resources are database dependant.&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Sat, 16 May 2009 16:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/m-p/6244#M1984</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-05-16T16:46:01Z</dc:date>
    </item>
  </channel>
</rss>

