Chapter Contents |
Previous |
Next |
LOSTCARD |
Valid: | in a DATA step |
Category: | Action |
Type: | Executable |
Syntax | |
Without Arguments | |
Details | |
When to Use LOSTCARD | |
When LOSTCARD Executes | |
Examples | |
See Also |
Syntax |
LOSTCARD; |
Details |
When SAS reads multiple records to create a single observation, it does not discover that a record is missing until it reaches the end of the data. If there is a missing record in your data, the values for subsequent observations in the SAS data set may be incorrect. Using LOSTCARD prevents SAS from reading a record from the next group when the current group has fewer records than SAS expected.
LOSTCARD is most useful when the input data have a fixed
number of records per observation and when each record for an observation
contains an identification variable that has the same value. LOSTCARD usually
appears in conditional processing, for example, in the THEN clause of an IF-THEN
statement, or in a statement in a SELECT group.
When LOSTCARD executes, SAS takes these steps:
Examples |
This example uses the LOSTCARD statement in a conditional construct to identify missing data records and to resynchronize the input data:
data inspect; input id 1-3 age 8-9 #2 id2 1-3 loc #3 id3 1-3 wt; if id ne id2 or id ne id3 then do; put 'DATA RECORD ERROR: ' id= id2= id3=; lostcard; end; datalines; 301 32 301 61432 301 127 302 61 302 83171 400 46 409 23145 400 197 411 53 411 99551 411 139 ;The DATA step reads three input records before writing an observation. If the identification number in record 1 (variable ID) does not match the identification number in the second record (ID2) or third record (ID3), a record is incorrectly entered or omitted. The IF-THEN DO statement specifies that if an identification number is invalid, SAS prints the message that is specified in the PUT statement message and executes the LOSTCARD statement.
In this example, the third record for the second observation (ID3=400) is missing. The second record for the third observation is incorrectly entered (ID=400 while ID2=409). Therefore, the data set contains two observations with ID values 301 and 411. There are no observations for ID=302 or ID=400. The PUT and LOSTCARD statements write these statements to the SAS log when the DATA step executes:
DATA RECORD ERROR: id=302 id2=302 id3=400 NOTE: LOST CARD. RULE:----+----1----+----2----+----3----+----4----+----5----+---- 4 302 61 5 302 83171 6 400 46 DATA RECORD ERROR: id=302 id2=400 id3=409 NOTE: LOST CARD. 7 409 23145 DATA RECORD ERROR: id=400 id2=409 id3=400 NOTE: LOST CARD. 8 400 197 DATA RECORD ERROR: id=409 id2=400 id3=411 NOTE: LOST CARD. 9 411 53 DATA RECORD ERROR: id=400 id2=411 id3=411 NOTE: LOST CARD. 20 411 99551 |
The numbers 14, 15, 16, 17, 18, 19, and 20 are line numbers in the SAS log.
See Also |
Statement:
|
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.