The
data set Sasuser.Admit contains health information about patients
in a clinic, their activity level, height, and weight. Suppose you
want to create a subset of the data. Specifically, you want to create
a small data set containing data about all the men in the group who
are older than 50.
To create the data set, you must first reference the
library in which Sasuser.Admit is stored. Then you must specify the
name of the library in which you want to store the Males data set.
Finally, you write a DATA step to read your data and create a new
data set.
Syntax, DATA step for
reading a single data set:
DATA SAS-data-set;
<...more
SAS statements...>
RUN;
-
SAS-data-set in
the DATA statement is the name of the SAS data set to be created.
-
SAS-data-set in
the SET statement is the name of the SAS data set to be read.
|
The DATA step below
reads all observations and variables from the existing data set Sasuser.Admit
into the new data set Males. The DATA statement creates the permanent
SAS data set Males, which is stored in the SAS library Men50. The
SET statement reads the permanent SAS data set Sasuser.Admit and subsets
the data using a WHERE statement. The new data set, Males, contains
all males in Sasuser.Admit who are older than 50.
libname sasuser "C:Users
amesasuser";
libname Men50 "C:Users
amesasuserMen50";
data Men50.males;
set sasuser.admit;
where sex='M' and age>50;
run;
When you submit this
DATA step, the following messages appear in the log, confirming that
the new data set was created:
Log 12.1 SAS Log Output
9226 data Men50.males;
9227 set sasuser.admit;
9228 where sex='M' and age>50;
9229 run;
NOTE: There were 3 observations read from the data set SASUSER.ADMIT.
WHERE (sex='M') and (age>50);
NOTE: The data set MEN50.MALES has 3 observations and 9 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
You can add a PROC PRINT
statement to this same example to see the output of Men50.Males.
proc print data=Men50.males;
title "Men Over 50";
run;