<?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: No of rows in a table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/880857#M348046</link>
    <description>I tried this it works abd display answer in log&lt;BR /&gt;But how to store the answer in a dataset?</description>
    <pubDate>Thu, 15 Jun 2023 04:34:29 GMT</pubDate>
    <dc:creator>HeatherNewton</dc:creator>
    <dc:date>2023-06-15T04:34:29Z</dc:date>
    <item>
      <title>No of rows in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/879778#M347568</link>
      <description>How can i get the no of rows in table A and output it as an input of a variable in another table?</description>
      <pubDate>Thu, 08 Jun 2023 15:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/879778#M347568</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2023-06-08T15:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: No of rows in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/879782#M347569</link>
      <description>&lt;P&gt;More than one way, as usual.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.listendata.com/2017/04/number-of-observations-in-sas-data.html" target="_blank"&gt;https://www.listendata.com/2017/04/number-of-observations-in-sas-data.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Probably the simplest to understand - note the table names are upper case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
 select nobs into :totobs separated by ' ' from dictionary.tables
 where libname='SASHELP' and memname='CARS';
quit;
%put total records = &amp;amp;totobs.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the &amp;amp;totobs value in the data step as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
x=&amp;amp;totobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Jun 2023 15:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/879782#M347569</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-06-08T15:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: No of rows in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/879783#M347570</link>
      <description>&lt;P&gt;Query the DICTIONARY tables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select nobs into :number
from dictionary.tables
where libname = "WORK" and memname = "A";
quit;

%put number of obs = &amp;amp;number.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Jun 2023 15:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/879783#M347570</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-08T15:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: No of rows in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/879802#M347573</link>
      <description>&lt;P&gt;This is a good situation to use the "IF 0 THEN SET .... NOBS=...;" statement, as in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if 0 then set table_a (drop=_all_) nobs=number_of_drivers;
  set sashelp.cars (keep=make model msrp);
  perdriver_cost=msrp/number_of_drivers;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Three points:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Even though &lt;EM&gt;&lt;STRONG&gt;IF 0&lt;/STRONG&gt;&lt;/EM&gt; is never true (so the &lt;EM&gt;&lt;STRONG&gt;"then SET" is never executed&lt;/STRONG&gt;&lt;/EM&gt;), the value for nobs (stored in &lt;EM&gt;&lt;STRONG&gt;number_of_drivers&lt;/STRONG&gt;&lt;/EM&gt;) is established prior to actual data processing.&amp;nbsp; So it's there for usage.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;Don't forget the "drop=_ALL_" dataset name parameter for table_a - that will eliminate columns of missing values for variables exclusive to table_a.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;The variable in the "nobs=" argument is not a permanent variable.&amp;nbsp; If you want it to be permanent, then modify the "if 0" to something like&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; if 0 then ...&amp;nbsp; nobs=xxx;&lt;/STRONG&gt;&lt;BR /&gt;followed by&amp;nbsp;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp; number_of_drivers=xxx;&lt;/STRONG&gt;&lt;BR /&gt;xxx will not be kept, but number_of_drivers will be.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;A nice feature of this approach is that it doesn't require using a separate procedure to get the number of observations, nor the creation of macrovars, or the use of special functions in the data step.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 16:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/879802#M347573</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-06-08T16:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: No of rows in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/879858#M347584</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
I prefer this code.
*/

%let dsid=%sysfunc(open(sashelp.class));
%let nobs=%sysfunc(attrn(&amp;amp;dsid.,nlobs));
%let dsid=%sysfunc(close(&amp;amp;dsid.));

%put sashelp.class has &amp;amp;nobs records.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 12:12:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/879858#M347584</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-06-09T12:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: No of rows in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/880348#M347845</link>
      <description>&lt;P&gt;why you dont need dot here after &amp;amp;totobs&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;x=&amp;amp;totobs;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 06:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/880348#M347845</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2023-06-13T06:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: No of rows in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/880352#M347847</link>
      <description>&lt;P&gt;If the macro variable name is not part of a longer string which&amp;nbsp;&lt;EM&gt;might&lt;/EM&gt; be a SAS name, the dot is not needed, but it is considered good practice (especially for beginners!) to always terminate a macro reference with a dot.&lt;/P&gt;
&lt;P&gt;Dot-terminated strings will also have distinct coloring in the Enhanced Editor.&lt;/P&gt;
&lt;P&gt;See Maxim 48.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 07:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/880352#M347847</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-13T07:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: No of rows in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/880841#M348033</link>
      <description>I tried but it is empty in table want, what could have gone wrong..</description>
      <pubDate>Wed, 14 Jun 2023 23:35:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/880841#M348033</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2023-06-14T23:35:02Z</dc:date>
    </item>
    <item>
      <title>Re: No of rows in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/880857#M348046</link>
      <description>I tried this it works abd display answer in log&lt;BR /&gt;But how to store the answer in a dataset?</description>
      <pubDate>Thu, 15 Jun 2023 04:34:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/880857#M348046</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2023-06-15T04:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: No of rows in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/880943#M348098</link>
      <description>Post your log please.</description>
      <pubDate>Thu, 15 Jun 2023 15:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/880943#M348098</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-06-15T15:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: No of rows in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/880956#M348104</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsid=%sysfunc(open(sashelp.class));
%let nobs=%sysfunc(attrn(&amp;amp;dsid.,nlobs));
%let dsid=%sysfunc(close(&amp;amp;dsid.));

%put sashelp.class has &amp;amp;nobs records.;

data num_records;
num_obs = &amp;amp;nobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the solution I posted, the table names need to be capitalized.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 15:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/No-of-rows-in-a-table/m-p/880956#M348104</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-06-15T15:23:11Z</dc:date>
    </item>
  </channel>
</rss>

