Before you can interleave data sets,
the data must be sorted by the same variable or variables that will
be used with the BY statement that accompanies your SET statement.
For example, the Research
and Development division and the Publications division of a company
both maintain data sets containing information about each project
currently under way. Each data set includes these variables:
Project
specifies a unique
code that identifies the project.
Department
specifies the name
of a department that is involved in the project.
Manager
specifies the last
name of the manager from Department.
StaffCount
specifies the number
of people working for Manager on this project.
Senior management for
the company wants to combine the data sets by Project so that the
new data set shows the resources that both divisions are devoting
to each project. Both data sets must be sorted by Project before they
can be interleaved.
The following program
creates and displays the data set RESEARCH_DEVELOPMENT. Note that
the input data is already sorted by Project.
data research_development;
length Department Manager $ 10;
input Project $ Department $ Manager $ StaffCount;
datalines;
MP971 Designing Daugherty 10
MP971 Coding Newton 8
MP971 Testing Miller 7
SL827 Designing Ramirez 8
SL827 Coding Cho 10
SL827 Testing Baker 7
WP057 Designing Hascal 11
WP057 Coding Constant 13
WP057 Testing Slivko 10
;
run;
proc print data=research_development;
title 'Research and Development Project Staffing';
run;
The following output
displays the RESEARCH_DEVELOPMENT data set:
Display 18.1 The RESEARCH_DEVELOPMENT Data Set
The following program
creates, sorts, and displays the second data set, PUBLICATIONS. Note
that the output data set is sorted by Project.
data publications;
length Department Manager $ 10;
input Manager $ Department $ Project $ StaffCount;
datalines;
Cook Writing WP057 5
Deakins Writing SL827 7
Franscombe Editing MP971 4
Henry Editing WP057 3
King Production SL827 5
Krysonski Production WP057 3
Lassiter Graphics SL827 3
Miedema Editing SL827 5
Morard Writing MP971 6
Posey Production MP971 4
Spackle Graphics WP057 2
;
run;
proc sort data=publications;
by Project;
run;
proc print data=publications;
title 'Publications Project Staffing';
run;
The following output
displays the PUBLICATIONS data set:
Display 18.2 The PUBLICATIONS Data Set