SAS Set Statement
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.
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.
附件列表
词条内容仅供参考,如果您需要解决具体问题
(尤其在法律、医学等领域),建议您咨询相关领域专业人士。
如果您认为本词条还有待完善,请 编辑
上一篇 SAS/CONNECT 下一篇 SAS Run Statement