Published on :
Data Manipulation INTERNAL_CREATION

DROP Statement

This code is also available in: Deutsch Español Français
Awaiting validation
The DROP statement applies to all SAS© datasets created within the same DATA step and can appear anywhere in the step. Variables specified in the DROP statement are available for processing within the DATA step. If no DROP or KEEP statement appears, all datasets created in the DATA step contain all variables. Do not use both DROP and KEEP statements in the same DATA step. If the same variable is listed in both DROP and KEEP statements, DROP takes precedence over KEEP, regardless of the order of the statements, and the variable is dropped.
Comparisons:
  • The DROP statement differs from the DROP= dataset option in several ways: the DROP statement cannot be used in SAS© procedure steps, and it applies to all output datasets named in the DATA statement. To exclude variables from some datasets but not others, use the DROP= dataset option.
  • The KEEP statement is a parallel statement that specifies a list of variables to write to output datasets. Use the KEEP statement rather than the DROP statement if the number of variables to include is significantly less than the number to omit.
  • Do not confuse the DROP statement with the DELETE statement. The DROP statement excludes variables from output datasets; the DELETE statement excludes observations.
Data Analysis

Type : INTERNAL_CREATION


Examples use generated data (datalines) to ensure their autonomy.

1 Code Block
DATA STEP Data
Explanation :
This example shows how to use the DROP statement to exclude variables (Heure, Travail, NombreLot) from a dataset created with DATALINES. Only the variables ID, Nom, Age, and Salaire will be kept in the final dataset MonJeuDeDonnees.
Copied!
1DATA MonJeuDeDonnees;
2 INPUT ID Nom $ Age Salaire Heure Travail NombreLot;
3 DROP Heure Travail NombreLot;
4DATALINES;
51 John 30 5000 8 1 101
62 Jane 25 4500 7 2 102
73 Mike 35 6000 9 1 103
8;
9RUN;
10 
11PROC PRINT DATA=MonJeuDeDonnees;
12RUN;
2 Code Block
DATA STEP Data
Explanation :
This example illustrates dropping a range of variables (Note1 to Note3) from a dataset. Only the variables Etudiant, Note4, and Note5 will be included in the ResultatsExamens dataset.
Copied!
1DATA ResultatsExamens;
2 INPUT Etudiant $ Note1 Note2 Note3 Note4 Note5;
3 DROP Note1-Note3;
4DATALINES;
5Alice 15 12 18 10 14
6Bob 10 14 11 16 9
7Charlie 18 16 19 15 17
8;
9RUN;
10 
11PROC PRINT DATA=ResultatsExamens;
12RUN;
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