<?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: Check the number of a data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667222#M199747</link>
    <description>&lt;P&gt;Don't forget to close the datasets you opened with the OPEN() function call.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jul 2020 16:06:27 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-07-06T16:06:27Z</dc:date>
    <item>
      <title>Check the number of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667203#M199734</link>
      <description>&lt;P&gt;Hello folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking for a way to check the number of rows for several data sets in a library.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Say I have Dsn1, Dsn2 and Dsn3 stored in a library called A, and I only want to execute the process on the data sets which has more than 10 rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using&amp;nbsp;%if %sysfunc(attrn(A.Dsn&amp;amp;i,nobs))&amp;gt;10 %then %do;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, sas told me attrn referenced by %sysfunc is not a number. Any idea?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 15:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667203#M199734</guid>
      <dc:creator>liyongkai800</dc:creator>
      <dc:date>2020-07-06T15:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: Check the number of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667213#M199738</link>
      <description>&lt;P&gt;Show us the LOG for these steps, without you deleting anything. We need to see the code you are using, as seen in the log, and we need to see the exact error message, as seen in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please format the log so it will be readable. Click on the &amp;lt;/&amp;gt; icon and then paste the log as text into the window that appears. DO NOT SKIP THIS STEP.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 15:34:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667213#M199738</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-06T15:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: Check the number of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667215#M199740</link>
      <description>&lt;P&gt;The first argument of the &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p12uchp7hm5h2zn1om2ut816af7h.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;ATTRN() function&lt;/A&gt; is the dataset identifier, not a dataset name. Here is an example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsid=%sysfunc(open(sashelp.cars));
%if %sysfunc(attrn(&amp;amp;dsid,nobs))&amp;gt;10 %then %do;
    %put Yes, there are more than 10 records.;
%end;
%let rc=%sysfunc(close(&amp;amp;dsid));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For your scenario, where you have three datasets in a single library, you could use a loop within a macro to dynamically evaluate their row counts:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* checking the row counts in work.test1, work.test2 and work.test3 */
%macro obs_count;
    %do i = 1 %to 3;
        %let dsid&amp;amp;i=%sysfunc(open(WORK.TEST&amp;amp;i));
        %if %sysfunc(attrn(&amp;amp;&amp;amp;dsid&amp;amp;i,nobs))&amp;gt;10 %then %do;
            %put Yes, there are more than 10 records in WORK.TEST&amp;amp;i;
        %end;
        %let rc=%sysfunc(close(&amp;amp;&amp;amp;dsid&amp;amp;i));
    %end;
%mend;
%obs_count;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;EM&gt;Edit: Close the datasets after completed. (Thanks for catching that,&lt;/EM&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;)&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 16:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667215#M199740</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-07-06T16:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Check the number of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667220#M199745</link>
      <description>&lt;P&gt;Alternative way is to check dictionary of sas by:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select LIBNAME, MEMNAME, NOBS
  from dictionary.tables 
  where libname = "SASHELP" and nobs &amp;gt; 10;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jul 2020 15:55:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667220#M199745</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-07-06T15:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: Check the number of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667222#M199747</link>
      <description>&lt;P&gt;Don't forget to close the datasets you opened with the OPEN() function call.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 16:06:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667222#M199747</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-06T16:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: Check the number of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667257#M199768</link>
      <description>&lt;P&gt;Query DICTIONARY.TABLES (SQL) or SASHELP.VTABLE (data/proc step).&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 18:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667257#M199768</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-06T18:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: Check the number of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667423#M199862</link>
      <description>Thanks, you are right. The argument in the open function should not be a data set.</description>
      <pubDate>Tue, 07 Jul 2020 12:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-the-number-of-a-data-set/m-p/667423#M199862</guid>
      <dc:creator>liyongkai800</dc:creator>
      <dc:date>2020-07-07T12:15:10Z</dc:date>
    </item>
  </channel>
</rss>

