Conditionally Processing Observations from Multiple SAS Data Sets |
To create a data set that contains only the observations that are selected according to a particular criterion, you can use the subsetting IF statement and a SET statement that specifies multiple data sets. The following DATA step reads two input data sets to create a combined data set that lists only the winning teams:
data champions(drop=result);1 set southamerican (in=S) european;2 by Year; if result='won';3 if S then Continent='South America';4 else Continent='Europe'; run; proc print data=champions; title 'World Cup Champions from 1954 to 1998'; title2 'including Countries'' Continent'; run;
The following list corresponds to the numbered items in the preceding program:
The following output shows the resulting data set CHAMPIONS:
Combining Selected Observations
World Cup Champions from 1954 to 1998 2 including Countries' Continent Obs Year Country Score Continent 1 1954 West Germany 3-2 Europe 2 1958 Brazil 5-2 South America 3 1962 Brazil 3-1 South America 4 1966 England 4-2 Europe 5 1970 Brazil 4-1 South America 6 1974 West Germany 2-1 Europe 7 1978 Argentina 3-1 South America 8 1982 Italy 3-1 Europe 9 1986 Argentina 3-2 South America 10 1990 West Germany 1-0 Europe 11 1994 Brazil 3-2 South America 12 1998 France 3-0 Europe
Copyright © 2012 by SAS Institute Inc., Cary, NC, USA. All rights reserved.