KEEP Statement:

KEEP names the variables in the output dataset. If the KEEP statement is not used, all variables, including those created during the DATA step, will be in the output dataset.

Syntax:
KEEP variable-list.

Arguments:
variable-list specifies the names of the variables to write to the output data set. You can list the variables in any form that SAS allows.

Example:

Often the researcher may only want to examine NDC, date, days supply, and quantity on the pharmacy claims, but the dataset often contains many other variables, including cost and administrative variables. It is more efficient to use the keep statement to limit variables to the fewest needed.

Keep Statement

DROP Statement:

DROP statement names the variables you want dropped from the output dataset. DROP is used when there are fewer variables to drop than to keep in the output dataset. If you want to keep 35 variables but only drop 5 variables, it is easier to use to DROP statement.

Syntax:
DROP variable-list;

Arguments:
variable-list specifies the names of the variables to omit from the output data set. You can list the variables in any form that SAS allows.

Example:

Service claims data often contain variables researchers may not need or want. In the example below, the claims file contains the recipient's age, sex, race, and county of residence. The researcher already has another dataset with demographic information on each patient, so the final claims dataset can exclude these variables. The service claims file has a total of 65 variables so it is far simpler to use the DROP statement to exclude the four demographic variables than to name 61 variables in a KEEP statement.

Drop Statement

KEEP= Option:

KEEP= option is similar to the KEEP statement. The KEEP= option is associated with a specific dataset. This means the keep= option can both used on both input and output datasets. The KEEP statement only applies to the output dataset.

Syntax:
KEEP=variable-1 <...variable-n>

Arguments:
variable-1 <...variable-n> lists one or more variable names. You can list the variables in any form that SAS allows.

Example:

In this example, the programmer limits the variables on the input dataset and then creates new variables using these variables. This is more efficient, resulting in a faster program, than having SAS read in all the variables on the original dataset and then using the KEEP statement.

Keep= option

DROP= Option:

DROP= option works in the same manner of KEEP= option. As with the KEEP= option, it can be used on both in the input and output datasets.

Syntax:
DROP=variable-1 <...variable-n>

Arguments:
variable-1 <...variable-n> lists one or more variable names. You can list the variables in any form that SAS allows.

Example:

One way of using DROP= or KEEP= is on the output datasets when you want to create two datasets: one for checking variable creation and one as a final dataset.

Drop= option