Usage Note 34609: Why is NOBS returning n observations when there are 0 observations in the data set?
The code below can be used to store the number of observations from a data set in a macro variable, &NUM.
%let dsid=%sysfunc(open(dataset_name));
%let num=%sysfunc(attrn(&dsid,nobs));
%let rc=%sysfunc(close(&dsid));
In some cases &NUM may resolve to a non-zero value even if there are 0 observations in the data set. This is due to the way the attribute treats observations marked for deletion and active WHERE clauses.
The NOBS attribute counts the number of physical observations including those marked for deletion. If a non-zero value is returned when 0 is expected, consider using NLOBS or NLOBSF instead. NLOBS counts the number of logical observations and does not include those marked for deletion. NLOBSF is the same as NLOBS and also takes the FIRSTOBS system option, the OBS system option, and the WHERE clauses into account.
%let num=%sysfunc(attrn(&dsid,nlobs));
%let num=%sysfunc(attrn(&dsid,nlobsf));
Operating System and Release Information
SAS System | Base SAS | z/OS | 9.1 TS1M3 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M3 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.1 TS1M3 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.1 TS1M3 | |
Microsoft Windows XP 64-bit Edition | 9.1 TS1M3 | |
Microsoft® Windows® for x64 | 9.1 TS1M3 | |
Microsoft Windows 2000 Advanced Server | 9.1 TS1M3 | |
Microsoft Windows 2000 Datacenter Server | 9.1 TS1M3 | |
Microsoft Windows 2000 Server | 9.1 TS1M3 | |
Microsoft Windows 2000 Professional | 9.1 TS1M3 | |
Microsoft Windows NT Workstation | 9.1 TS1M3 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.1 TS1M3 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.1 TS1M3 | |
Microsoft Windows Server 2003 Standard Edition | 9.1 TS1M3 | |
Microsoft Windows XP Professional | 9.1 TS1M3 | |
Windows Vista | 9.1 TS1M3 | |
64-bit Enabled AIX | 9.1 TS1M3 | |
64-bit Enabled HP-UX | 9.1 TS1M3 | |
64-bit Enabled Solaris | 9.1 TS1M3 | |
HP-UX IPF | 9.1 TS1M3 | |
Linux | 9.1 TS1M3 | |
OpenVMS Alpha | 9.1 TS1M3 | |
Tru64 UNIX | 9.1 TS1M3 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
When checking to see if there are no observations in a data set, NOBS is returning a value of 1 or greater when it should be returning a 0.
Date Modified: | 2009-01-28 12:50:28 |
Date Created: | 2009-01-27 12:46:20 |