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!
DATA MonJeuDeDonnees;
INPUT ID Nom $ Age Salaire Heure Travail NombreLot;
DROP Heure Travail NombreLot;
DATALINES;
1 John 30 5000 8 1 101
2 Jane 25 4500 7 2 102
3 Mike 35 6000 9 1 103
;
RUN;
PROC PRINT DATA=MonJeuDeDonnees;
RUN;
1
DATA MonJeuDeDonnees;
2
INPUT ID Nom $ Age Salaire Heure Travail NombreLot;
3
DROP Heure Travail NombreLot;
4
DATALINES;
5
1 John 30500081101
6
2 Jane 25450072102
7
3 Mike 35600091103
8
;
9
RUN;
10
11
PROC PRINTDATA=MonJeuDeDonnees;
12
RUN;
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!
DATA ResultatsExamens;
INPUT Etudiant $ Note1 Note2 Note3 Note4 Note5;
DROP Note1-Note3;
DATALINES;
Alice 15 12 18 10 14
Bob 10 14 11 16 9
Charlie 18 16 19 15 17
;
RUN;
PROC PRINT DATA=ResultatsExamens;
RUN;
1
DATA ResultatsExamens;
2
INPUT Etudiant $ Note1 Note2 Note3 Note4 Note5;
3
DROP Note1-Note3;
4
DATALINES;
5
Alice 1512181014
6
Bob 101411169
7
Charlie 1816191517
8
;
9
RUN;
10
11
PROC PRINTDATA=ResultatsExamens;
12
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.