The DELETE statement is used to exclude observations from a data set. When this statement is executed, the current observation is not written to the output data set, and execution 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 conditionally executed DO group. Unlike the DROP statement which excludes variables, DELETE excludes entire observations. It is preferred when the condition for excluding observations is simpler to specify.
Data Analysis
Type : INTERNAL_CREATION
Examples use raw data (infile) or conditions on existing variables.
1 Code Block
DATA STEP
Explanation : This example shows the use of the DELETE statement to delete an observation when the value of the 'leafwt' variable is missing. If 'leafwt' is missing, the observation is deleted from the data set being built.
Copied!
if leafwt=. then delete;
1
IF leafwt=. THEN delete;
2 Code Block
DATA STEP Data
Explanation : This second example uses the DELETE statement to filter observations directly when reading raw data. The 'topsales' data set is created, and only observations where 'yrsales' is greater than or equal to 100000 are kept. Observations with 'yrsales' less than 100000 are deleted before being written to the output data set.
Copied!
data topsales;
infile datalines;
input region office product yrsales;
if yrsales<100000 then delete;
datalines;
North Sales A 120000
South Marketing B 80000
East HR C 150000
West Sales D 95000
;
run;
1
DATA topsales;
2
INFILEDATALINES;
3
INPUT region office product yrsales;
4
IF yrsales<100000THEN delete;
5
DATALINES;
6
North Sales A 120000
7
South Marketing B 80000
8
East HR C 150000
9
West Sales D 95000
10
;
11
RUN;
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.