The KEEP statement applies to all output data sets named in the DATA statement. To write different variables to different data sets, you must use the KEEP= data set option.
The DROP statement is a parallel statement that specifies which variables to omit from output data sets.
KEEP and DROP statements select variables to include or exclude from output data sets. The subsetting IF statement selects observations.
Explanation : These examples show the correct syntax for listing variables in the KEEP statement.
Copied!
keep name address city state zip phone;
keep rep1-rep5;
1
keep name address city state zip phone;
2
keep rep1-rep5;
3
2 Code Block
DATA STEP Data
Explanation : This example uses the KEEP statement to include only the NAME and AVG variables in the output data set. Variables SCORE1 through SCORE20, from which AVG is calculated, are not written to the AVERAGE data set.
Copied!
data scores;
input name $ score1-score20;
datalines;
John 10 12 15 11 14 13 16 10 18 12 14 11 13 15 10 12 11 13 14 10 16
Jane 15 14 13 16 12 11 10 17 13 15 12 14 11 16 13 10 12 11 14 15
;
run;
data average;
set scores;
keep name avg;
avg=mean(of score1-score20);
run;
1
DATA scores;
2
INPUT name $ score1-score20;
3
DATALINES;
4
John 101215111413161018121411131510121113141016
5
Jane 1514131612111017131512141116131012111415
6
;
7
RUN;
8
9
DATA average;
10
SET scores;
11
keep name avg;
12
avg=mean(of score1-score20);
13
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.
« Remember that KEEP only controls what is written to the output. All variables remain available for calculations throughout the duration of the DATA step, regardless of where the KEEP statement is placed. »
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.