Prerequisites
Before using this section, you should understand the concepts that are presented in the
following sections:
Chapter 4, “Starting with Raw Data: The Basics,” on page 51
Chapter 6, “Starting with SAS Data Sets,” on page 91
Chapter 18, “Interleaving SAS Data Sets,” on page 281
Input SAS Data Sets for Examples
The following program creates two SAS data sets, SOUTHAMERICAN and
EUROPEAN. Each data set contains the following variables:
Year
is the year in which South American and European countries competed in the World
Cup Finals from 1954 to 1998.
Country
is the name of the competing country.
Score
is the final score of the game.
Result
is the result of the game. The value for winners is won; the value for losers is lost.
The PROC SORT statements in the example below sort the data sets in ascending order
according to the BY variable. To create the interleaved data set in the next example, the
data must be in ascending order.
data southamerican;
title 'South American World Cup Finalists from 1954 to 1998';
input Year $ Country $ 9-23 Score $ 25-28 Result $ 32-36;
datalines;
1998 Brazil 0-3 lost
1994 Brazil 3-2 won
1990 Argentina 0-1 lost
1986 Argentina 3-2 won
1978 Argentina 3-1 won
1970 Brazil 4-1 won
1962 Brazil 3-1 won
1958 Brazil 5-2 won
;
data european;
title 'European World Cup Finalists From 1954 to 1998';
input Year $ Country $ 9-23 Score $ 25-28 Result $ 32-36;
datalines;
1998 France 3-0 won
1994 Italy 2-3 lost
1990 West Germany 1-0 won
1986 West Germany 2-3 lost
1982 Italy 3-1 won
350 Chapter 22 Conditionally Processing Observations from Multiple SAS Data Sets
1982 West Germany 1-3 lost
1978 Netherlands 1-3 lost
1974 West Germany 2-1 won
1974 Netherlands 1-2 lost
1970 Italy 1-4 lost
1966 England 4-2 won
1966 West Germany 2-4 lost
1962 Czechoslovakia 1-3 lost
1958 Sweden 2-5 lost
1954 West Germany 3-2 won
1954 Hungary 2-3 lost
;
run;
proc sort data=southamerican;
by year;
proc print data=southamerican;
title 'World Cup Finalists:';
title2 'South American Countries';
title3 'from 1954 to 1998';
run;
proc sort data=european;
by year;
run;
proc print data=european;
title 'World Cup Finalists:';
title2 'European Countries';
title3 'from 1954 to 1998';
run;
The PROC SORT statement sorts the data set in ascending order according to the BY
variable. To create the interleaved data set in the next example, the data must be in
ascending order.
Input SAS Data Sets for Examples 351
The following output displays the SOUTHAMERICAN data set:
Figure 22.1 World Cup Finalists by Continent: South America
352 Chapter 22 Conditionally Processing Observations from Multiple SAS Data Sets

Get Step-by-Step Programming with Base SAS 9.4, Second Edition, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.