Usage Note 43338: The FIRSTOBS= data set option retrieves the first observation available after deleting observations through the Viewtable window
The FIRSTOBS= data set option retrieves the first observation available after deleting observations through the Viewtable window.
Problem
Observations can be deleted through the Viewtable window when Edit Mode is activated. The Viewtable window can be accessed through the SAS® Explorer window, or by issuing the VIEWTABLE or VT command on the data set. After deleting an observation through the Viewtable window, using the FIRSTOBS= data set option gives incorrect results if the value assigned to FIRSTOBS is greater than the number of the observation deleted.
For an illustration, follow these steps:
- Create a simple data set.
data test;
a=1; b=10; output;
a=2; b=20; output;
a=3; b=30; output;
a=4; b=40; output;
a=5; b=50; output;
run;
- Open the data set from the SAS Explorer window, turn on Edit Mode from the Edit menu, and delete the third observation where A=3.
- Run the following DATA step code:
data test3;
set test (firstobs=3);
run;
This gives correct results. Since the original observation with A=3 has been deleted, the updated FIRSTOBS=3 is the observation with A=4.
- Run the following DATA step code:
data test4;
set test (firstobs=4);
run;
This gives incorrect results. It should return observations starting with the new fourth one, where A=5. However, it returns observations with A=4 and with A=5.
Workaround
There are two options for workarounds:
- Do not delete observations through the Viewtable window.
- If you do delete observations through the Viewtable window, re-create the data set using a DATA step or PROC SORT before using FIRSTOBS=.
For example, do the following before running step 4 above:
data test;
set test;
run;
Explanation
This behavior occurs because deleting data set observations using these methods deletes the observations in-place and only flags the observation for deletion. It does not physically remove the observation; it makes it unusable. When observations are deleted using PROC SQL or the DATA step, the observations are physically deleted and removed from the data set.
Operating System and Release Information
| SAS System | Base SAS | HP-UX IPF | 9.2 TS2M0 | |
| 64-bit Enabled Solaris | 9.2 TS2M0 | |
| 64-bit Enabled HP-UX | 9.2 TS2M0 | |
| 64-bit Enabled AIX | 9.2 TS2M0 | |
| Windows Vista for x64 | 9.2 TS2M0 | |
| Windows Vista | 9.2 TS2M0 | |
| Microsoft Windows XP Professional | 9.2 TS2M0 | |
| Microsoft Windows Server 2008 for x64 | 9.2 TS2M0 | |
| Microsoft Windows Server 2008 R2 | 9.2 TS2M0 | |
| Microsoft Windows Server 2003 for x64 | 9.2 TS2M0 | |
| Microsoft Windows Server 2003 Standard Edition | 9.2 TS2M0 | |
| Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS2M0 | |
| Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS2M0 | |
| Microsoft® Windows® for x64 | 9.2 TS2M0 | |
| Microsoft Windows XP 64-bit Edition | 9.2 TS2M0 | |
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS2M0 | |
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS2M0 | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS2M0 | |
| z/OS | 9.2 TS2M0 | |
| Linux | 9.2 TS2M0 | |
| Linux for x64 | 9.2 TS2M0 | |
| OpenVMS on HP Integrity | 9.2 TS2M0 | |
| Solaris for x64 | 9.2 TS2M0 | |
*
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.
| Type: | Usage Note |
| Priority: | medium |
| Topic: | SAS Reference ==> DATA Step
|
| Date Modified: | 2011-06-27 10:49:23 |
| Date Created: | 2011-05-24 09:57:32 |