The following output displays the results.
Figure 12.7 Selecting One Observation from Each BY Group
Working with Sorted Data
Understanding Sorted Data
By default, groups appear in ascending order of the BY values. In some cases you want
to emphasize the order in which the observations are sorted, not the fact that they can be
grouped. For example, you might want to alphabetize the tours by country.
To sort your data in a particular order, use the SORT procedure just as you do for
grouped data. When the sorted order is more important than the grouping, you usually
want only one observation with a given BY value in the resulting data set. Therefore,
you might need to remove duplicate observations.
Operating Environment Information
The SORT procedure accesses either a sorting utility that is supplied as part of SAS,
or a sorting utility that is supplied by the host operating environment. All examples
in this documentation use the SAS sorting utility. Some operating environment
utilities do not accept particular options, including the NODUPRECS option
described later in this section. The default sorting utility is set by your site. For more
information about the utilities available to you, see the documentation for your
The following example sorts data set MYLIB.ARCH_OR_SCEN by Country:
proc sort data=mylib.arch_or_scen out=bycountry;
proc print data=bycountry;
title 'Tours in Alphabetical Order by Country';
192 Chapter 12 • Working with Grouped or Sorted Observations