Format:
b = delete(group[occ]);
[occ] is required for multiply-occurring records or items; is not required for singly-occurring records or items
Description:
The delete function removes incomplete, or otherwise unneeded, records or item occurrences from the current case. It can be used to remove singly- or multiply-occurring records, although if the record is non-repeating (such as the housing record in a typical census application), then it must be defined as "required=no" in the dictionary. This function was primarily intended for batch applications. It should be used with extreme caution in data entry applications because of possible conflicts between the operator's actions and the program logic.
Return value:
The function returns a logical value 1 (true) if successful and 0 (false) otherwise.
Example 1 (for multiply-occurring records):
do varying i = totocc(PERSON_REC) until i <= 0 by (-1)
if rel(i) = notappl and
sex(i) = notappl and
age(i) = notappl then
delete (PERSON_REC(i)); { remove "blank" person records }
endif;
enddo;
In this example blank person records are deleted from the case. Records following any deleted record are 'shifted up' to cover the vacated area. For example, if you delete the 2nd of four records, the 3rd record shifts to the 2nd position and the 4th records shifts to the 3rd position.
It is best to delete the records starting with the last record and moving toward the first. Use a subscript that starts at the last occurrence then is decremented [decreased by 1]. In this way you will not need to worry about the records that are shifting positions.
Example 2 (for singly-occurring records):
if h01_type = 6 then { person is homeless, delete record }
delete (HOUSING); { notice the absence of a subscript }
endif;
See also: If Statement, Totocc Function, Do Statement