SAS Programming: Data Set Options

The SAS system contains several data options that play an important part in fine tuning SAS programs.  This post will focus on several options that can be included in the “data” commands when reading in data. These options will tell SAS which variables to keep, drop, and rename certain variables.  Other options tell SAS what observation to start reading from when importing.  The data used will be the GDP by state figures for 2010 that were merged together with the state name and state capital database in the previous post.


The keep option tells SAS which variables to keep in the data set.  The following code creates a new data set and keeps the variables “abbreviation”, “gdp”, and “name”.  Notice that the variable capital is not included because it was left out of the “keep” option.

Another way of eliminating the “capital” variable is to use the “drop” statement.

The options above can help to eliminate unnecessary variables that tend to accumulate when merging data.  Finally, the last option of this post concerns itself with renaming variables within a data set.  This command can either be used to create a new data set with the updated names or replace an existing data set with the new variable names.  The code below creates a new data set where the variables “gdp” and “names” have been renamed to “income” and “state” respectively.

Finally, it may be useful to print a subset of the data.  This can be accomplished by using the “firstobs” and the “obs” options only with the “proc print” command.

Notice how the “first obs = 2” command ensured that the output skipped the first state which was Alaska.  The second command “obs = 5” ensured that only the 5 observations were printed.  Noticed that the “obs” command begins with the original observation no matter where SAS is told to start with the “firstobs” command.