Published on :
Action INTERNAL_CREATION

DELETE Statement

This code is also available in: Deutsch Español Français
Awaiting validation
The DELETE statement is used in a DATA step to stop processing the current observation. When DELETE is executed, the current observation is not written to the data sets created by the DATA step, and control immediately returns to the beginning of the DATA step for the next iteration. It is often used in a THEN clause of an IF-THEN statement or in a DO group executed conditionally. Unlike the DROP statement, which excludes variables from an output data set, DELETE excludes entire observations.
Data Analysis

Type : INTERNAL_CREATION


Examples use generated data (datalines).

1 Code Block
DATA STEP Data
Explanation :
This example creates a data set 'new_data'. It reads the variables 'id' and 'leafwt'. If the value of 'leafwt' is missing (represented by '.'), the DELETE statement is executed, which removes the entire observation from the final data set. Only observations with a non-missing value for 'leafwt' will be included in 'new_data'.
Copied!
1DATA new_data;
2 INPUT id leafwt;
3 DATALINES;
4 1 10.5
5 2 .
6 3 25.3
7 4 .
8 5 18.0
9 ;
10 IF leafwt=. THEN delete;
11RUN;
12 
13PROC PRINT DATA=new_data;
14 title 'Observations after deleting missing values of LEAFWT';
15RUN;
2 Code Block
DATA STEP Data
Explanation :
This example reads in-line raw data (simulating an external file via 'infile datalines'). It creates a 'topsales' data set. For each observation read, it checks if the value of 'yrsales' (annual sales) is less than 100,000. If so, the DELETE statement is executed, excluding that observation from the 'topsales' data set. The final 'topsales' data set will only contain observations where 'yrsales' is greater than or equal to 100,000.
Copied!
1DATA topsales;
2 INFILE DATALINES;
3 INPUT region $ office $ product $ yrsales;
4 IF yrsales<100000 THEN delete;
5 DATALINES;
6 East Boston Hardware 120000
7 West LA Software 95000
8 North Chicago Electronics 200000
9 South Miami Services 80000
10 Central Dallas Retail 150000
11 ;
12RUN;
13 
14PROC PRINT DATA=topsales;
15 title 'Annual Sales Greater Than 100,000';
16RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright © SAS Institute Inc. All Rights Reserved