I don't really understand how the n+1 statement could be used to solve the problem, for I don't really want to add a variable n in the dataset. (Or how does one use the n+1 statement without creating a variable named "n"?) My problem is that, whereas the final dataset has only 4 observations, SAS somehow has a reference to 5 observations (as illustrated by the last piece of code).
The example provided is only an illustration of the problem. Actually I am working with a large dataset, from which I remove the last 5% or so of the data. I then add new data using PROC APPEND, because I don't want to rewrite all the data in the original dataset. Afterwards, I am using a custom binary search using the POINT = statement. But this is exactly where the problem comes in that is illustrated by the example.
The problem, as in the example, is that when the second observation is removed from the first dataset, if you open the table in SAS Viewer, the row numbers of the remaining to records are 1 and 3, and not 1 and 2 as one would have expected. And when using the POINT = statement, it corresponds to what you see in the SAS Viewer: there still are row number references to 3 observations.
Sorry, I don't understand how this will solve the problem: I don't want to remove the observation in which AcctNumber=1005. I need the row number references (or table vector or whatever it is called) of the final accounts-table to be 1, 2, 3, 4 rather than: 1,2,4,5.
Thank you. But as far as I know, the code that you are suggesting:
if AcctNumber=1002 then delete;
... rewrites the accounts table (due to the SET statement). I know that the code you are suggesting will work, but my problem is that I have a fairly large dataset and I only want to remove the last part (about 5%) of the dataset. If I use the delete statement with the set statement, the other 95% of the data still gets rewritten (is that not so?) - and that is what I want to avoid, but without getting the observation references mixed up.
Closest I could get to resolving the problem thus far:
There is something like a PURGE statement, which seems to renumber records.
The only problem is: the statement is used in PROC IML
(http://support.sas.com/documentation/cdl/en/imlug/59656/HTML/default/langref_sect207.htm) and we do not have PROC IML.
The function can also be used elsewhere:
However, I can see no where that it can be used in a datastep without the SET statement or in PROC SQL.
Message was edited by: PHK
When you MODIFY a data set and REMOVE an obs the record is not physically removed but somehow internally flagged as being deleted.
When reading a SAS data set using direct access with SET and the POINT option when you point to a REMOVED record the SET fails and sets _ERROR_ = 1. The NOBS option gives the “physical” record count which includes any REMOVED records. You can detect the removed records by examination of _ERROR_ and take appropriate action. Note also that when SET fails for a REMOVED record the variables being read by the SET statement will retain the values from the last successful SET.
I don’t know if this will help you or not. If you explain in detail what you need to do with the data with removed records perhaps someone can help you.
input AcctNumber Credit @@;
1001 1500 1002 4900 1003 3000
if AcctNumber=1002 then remove;
input AcctNumber Credit @@;
1004 3800 1005 9200
proc append base = accounts data = accounts2;
do point = 1 to nobs;
_error_ = 0;
set accounts point=point nobs=nobs;
if _error_ eq 1 then do;
put 'NOTE: OBS ' point 'is not Accessible';
call missing(of _all_);