1.

What are different ways to exclude or include specific variables in a dataset?

Answer»

DROP and KEEP statements can be used to exclude or include specific variables from a data set. 

  • Drop Statement: This instructs SAS which variables to remove from the data set.
  • Keep Statement: The variables in the data set to be retained are specified using this statement.

Example: Consider the following data set: 

DATA outdata; INPUT gender $ section score1 score2; DATALINES; F A 17 20 F B 25 17 F C 12 15 M D 21 25 ; proc print; run;

The following DROP statement instructs SAS to drop variables score1 and score2. 

data readin; set outdata; totalsum = sum(score1,score2); drop score1, score2; run;

Output:  

Gender Section totalsum F A 37 F B 42 F C 27M D 46

The following KEEP statement instructs SAS to RETAIN score1 in the data set. 

data readin1; set readin; keep score1; run;

Output:  

Gender Section score1 totalsum F A 17 37 F B 25 42 F C 12 27 M D 21 46


Discussion

No Comment Found