Set Statement

Contents Index


The set statement is used to modify an existing SAS data set.

As an example, suppose the data set course contains variables m1-m3 and final. A new variable grade can be added to the data set as follows:

data course;
set course;
grade=(m1+m2+m3)/3+final;
run;

A new data set could have been created by changing the first line:

data new;
set course;
grade=(m1+m2+m3)/3 +final;
run;

Variables can be eliminated from an existing data set in a similar way using drop or keep. Example:

data new;
set course;
drop m1-m3;
run;

Data records can be deleted from a data set using either the where statement or subsetting if statement. As an example, suppose the data set rain contains yearly rainfall by city for the years 1900-1994. The variables in the data set are year, rainfall, and city. Then

data aurain;
set rain;
where year >= 1970 and city='auburn';
run;

creates a new data set containing auburn rainfall data for the years 1970-1994. This could also be accomplished using:

data aurain;
set rain;
if year >= 1970 and city='auburn';
run;

Two (or more) data sets can be concatenated (joined) together using set:

data new;
set first second;
run;

The data set new consists of all of the observations in the data sets first and second. This is useful when data is collected in batches at different points in time.


Contents Index

Copyright © 1997 by Jerry Alan Veeh. All rights reserved.