<?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: Getting number of observations in a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/204039#M306257</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You most probably have the dataset opened in a file window. Close that first.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another method for obtaining the record count:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;call symput('lastobs',put(lastobs,best.));&lt;/P&gt;&lt;P&gt;set a_counts nobs=lastobs;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now &amp;amp;lastobs will hold the number of observations in your dataset. Note the ordering of statements in the data step, which is crucial for it to work when the dataset has zero observations.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Jun 2015 06:07:42 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2015-06-12T06:07:42Z</dc:date>
    <item>
      <title>Getting number of observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/204036#M306254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;HI all,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;I have a dataset &lt;/SPAN&gt;a_counts,&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; If it has 0 observations, I have to skip a few steps.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; /*Open dataset*/&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;myDS=&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;(open(a_counts,i));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;/*Get number of observations*/&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; iswhere=&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;(attrn(&amp;amp;myDS,nobs));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;*/DO a few steps if there is data*/&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; &amp;amp;ISWHERE ne &lt;/SPAN&gt;&lt;STRONG style=": ; color: #008080; font-size: 10pt; font-family: Courier New;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;%then&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;%do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;But this is giving me the following error:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You cannot open WORK.A_COUNTS.DATA for output access with member-level control because WORK.A_COUNTS.DATA is in use by you in resource environment DMS Process.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please advise.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Archana&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Jun 2015 19:25:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/204036#M306254</guid>
      <dc:creator>ArchanaSudhir</dc:creator>
      <dc:date>2015-06-11T19:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: Getting number of observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/204037#M306255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have somehow opened this dataset previously in your SAS session. You either need to close this dataset for your code to work, or close SAS and restart SAS.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Jun 2015 19:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/204037#M306255</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-06-11T19:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Getting number of observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/204038#M306256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another way to get the same info without opening (and possibly forgetting to close a data set):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; select nobs into : iswhere&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; from dictionary.tables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; where libname='WORK' and memname='A_COUNTS';&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that the Libname and Memname must be in upper case OR use the upcase function on the literal value.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Jun 2015 22:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/204038#M306256</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-06-11T22:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Getting number of observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/204039#M306257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You most probably have the dataset opened in a file window. Close that first.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another method for obtaining the record count:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;call symput('lastobs',put(lastobs,best.));&lt;/P&gt;&lt;P&gt;set a_counts nobs=lastobs;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now &amp;amp;lastobs will hold the number of observations in your dataset. Note the ordering of statements in the data step, which is crucial for it to work when the dataset has zero observations.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jun 2015 06:07:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/204039#M306257</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-06-12T06:07:42Z</dc:date>
    </item>
  </channel>
</rss>

