<?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/73757#M15892</link>
    <description>The NOTE not ERROR is caused by the numeric to character conversion.  I would change as follows and move the STOP up.  But what you have still works.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   call symput('noobs',trim(put(noobs,f8.-l)));&lt;BR /&gt;
   stop;&lt;BR /&gt;
   set usdata(drop=_all_) nobs = noobs;&lt;BR /&gt;
   run;&lt;BR /&gt;
%put NOTE: noobs=&amp;amp;noobs;&lt;BR /&gt;
[/pre]

Added TRIM&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: data _null_;</description>
    <pubDate>Wed, 11 Feb 2009 14:59:24 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2009-02-11T14:59:24Z</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/73756#M15891</link>
      <description>Hi Dear,&lt;BR /&gt;
I am trying to get the number of observation in a dataset.When I wrote the below code in SAS 8.2 I got the followed error message. When wrote the same code in SAS 9.1 , I don't get any error message. Can any one explain why and let me know how to fix it.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your help in advance.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Inp&lt;BR /&gt;
DATA USDATA;&lt;BR /&gt;
 INPUT X $1.;&lt;BR /&gt;
 CARDS;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
    DATA _NULL_;&lt;BR /&gt;
    CALL SYMPUT('NOOBS', NOOBS);&lt;BR /&gt;
    SET USDATA NOBS = NOOBS;&lt;BR /&gt;
    STOP;&lt;BR /&gt;
    RUN;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I receive  the following message  for SAS 8.2&lt;BR /&gt;
DATA _NULL_;&lt;BR /&gt;
CALL SYMPUT('NOOBS', NOOBS);&lt;BR /&gt;
                     _____&lt;BR /&gt;
                     _____&lt;BR /&gt;
                     _____&lt;BR /&gt;
                     546&lt;BR /&gt;
                     546&lt;BR /&gt;
                     546&lt;BR /&gt;
NOTE 546-185: THE VARIABLE NOOBS MAY BE UNINITIALIZED</description>
      <pubDate>Wed, 11 Feb 2009 14:49:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/73756#M15891</guid>
      <dc:creator>Inp</dc:creator>
      <dc:date>2009-02-11T14:49:52Z</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/73757#M15892</link>
      <description>The NOTE not ERROR is caused by the numeric to character conversion.  I would change as follows and move the STOP up.  But what you have still works.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   call symput('noobs',trim(put(noobs,f8.-l)));&lt;BR /&gt;
   stop;&lt;BR /&gt;
   set usdata(drop=_all_) nobs = noobs;&lt;BR /&gt;
   run;&lt;BR /&gt;
%put NOTE: noobs=&amp;amp;noobs;&lt;BR /&gt;
[/pre]

Added TRIM&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: data _null_;</description>
      <pubDate>Wed, 11 Feb 2009 14:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/73757#M15892</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-02-11T14:59:24Z</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/73758#M15893</link>
      <description>Thanks so much. can you please explain what  is this  format f8.-l</description>
      <pubDate>Wed, 11 Feb 2009 15:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/73758#M15893</guid>
      <dc:creator>Inp</dc:creator>
      <dc:date>2009-02-11T15:14:51Z</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/73759#M15894</link>
      <description>&amp;gt; Thanks so much. can you please explain what  is this&lt;BR /&gt;
&amp;gt;  format f8.-l&lt;BR /&gt;
&lt;BR /&gt;
F is another name for the standard W.D format.  -L means left justify.  Could have used left(trim(put(nobs,8.)) would be the same result.  You want the value of the macro variable to be stripped of leading or trailing blank in most situations.&lt;BR /&gt;
&lt;BR /&gt;
I often "argue" on SAS-L that putting NOBS into a macro variable is almost always unnecessary, as most examples where NOBS is then used are really just trying to determine if the data is empty.&lt;BR /&gt;
&lt;BR /&gt;
Simplistic example:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   if _n_ eq 1 and eof then do;&lt;BR /&gt;
      /* processing for empty data set */&lt;BR /&gt;
      put 'NOTE: Data is empty';&lt;BR /&gt;
      end;&lt;BR /&gt;
   stop;&lt;BR /&gt;
   set usdata end=eof;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 11 Feb 2009 16:31:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/73759#M15894</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-02-11T16:31:36Z</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/73760#M15895</link>
      <description>Hi Thanks so much. I really really appriciated for your help Mr _NULL_.&lt;BR /&gt;
&lt;BR /&gt;
Thanks again.</description>
      <pubDate>Wed, 11 Feb 2009 17:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/73760#M15895</guid>
      <dc:creator>Inp</dc:creator>
      <dc:date>2009-02-11T17:07:33Z</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/73761#M15896</link>
      <description>Another way to get the number of observations is to use SASHELP as follows:&lt;BR /&gt;
&lt;BR /&gt;
DATA _NULL_;&lt;BR /&gt;
   SET SASHELP.VTABLE; &lt;BR /&gt;
    WHERE LIBNAME EQ ‘WORK’ AND MEMNAME EQ ‘EXAMPLE’;&lt;BR /&gt;
  CALL SYMPUTX(‘NOBS’,NOBS);&lt;BR /&gt;
 PUT “NOTE: Dataset WORK.EXAMPLE has “ NOBS “ observations.”;&lt;BR /&gt;
RUN; &lt;BR /&gt;
&lt;BR /&gt;
The SYMPUTX function is new in V9 and avoids having to use TRIM and LEFT functions.&lt;BR /&gt;
&lt;BR /&gt;
I usually struggle to find documentation about these SASHELP tables, but a search just now found it under ‘Concepts: SQL Procedure’.</description>
      <pubDate>Thu, 12 Feb 2009 09:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/73761#M15896</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-02-12T09:47:30Z</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/73762#M15897</link>
      <description>Another, a more direct way is to use the ATTRN function:&lt;BR /&gt;
&lt;BR /&gt;
%let dsid = %sysfunc(open(mytable));&lt;BR /&gt;
%let nobs= %sysfunc(attrn(&amp;amp;DSID,nobs));&lt;BR /&gt;
%put &amp;amp;NOBS;&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Thu, 12 Feb 2009 10:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/73762#M15897</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2009-02-12T10:18:54Z</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/73763#M15898</link>
      <description>Did you forget to close the door?&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
15   %let dsid = %sysfunc(open(mytable));&lt;BR /&gt;
16   %let nobs= %sysfunc(attrn(&amp;amp;DSID,nobs));&lt;BR /&gt;
17   %put &amp;amp;NOBS;&lt;BR /&gt;
1&lt;BR /&gt;
18   /*%let rc = %sysfunc(close(&amp;amp;dsid));*/&lt;BR /&gt;
19   %put NOTE: &amp;amp;dsid &amp;amp;rc;&lt;BR /&gt;
NOTE: 1 0&lt;BR /&gt;
20   proc sort data=mytable;&lt;BR /&gt;
21      by x;&lt;BR /&gt;
22      run;&lt;BR /&gt;
&lt;BR /&gt;
ERROR: You cannot open WORK.MYTABLE.DATA for output access with member-level control because&lt;BR /&gt;
WORK.MYTABLE.DATA is in use by you in resource environment SORT.&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 12 Feb 2009 13:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-number-of-observations-in-a-dataset/m-p/73763#M15898</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-02-12T13:38:03Z</dc:date>
    </item>
  </channel>
</rss>

