SUPPORT / SAMPLES & SAS NOTES
 

Support

Sample 31513: Outputting the largest value in a BY-Group in SAS® Enterprise Guide

DetailsAboutRate It

SAS® Enterprise Guide can be used to output the largest value in a BY group. The following steps demonstrate how to perform this task.

  1. Bring the SASHELP.CLASS dataset into the project to use as sample data.

  2. Select the data set in the project, then open the Sort task from Data–>Sort Data

    Sort task from pulldown menu

  3. Move the SEX, AGE, and HEIGHT variables over from Columns To Assign to Task Roles and put them under the Sort by role

  4. Select HEIGHT, and change the Height sort order from Ascending to Descending. This will ensure that the largest height is in the first observation for each SEX and AGE group.

    Order height by descending

  5. Run the Sort task. Now the data is sorted by Sex, Age, and Height.

    Sorted data

  6. Select the sorted data set and bring up the Sort Data task again. We are now going to create the final data set, which has the largest height for each age by sex.

  7. This time, sort by SEX and AGE. Under Options, go to Duplicate Records and select Keep only the first record for each 'Sort by' group. Run the Sort task to output the first record for our sex and age groupings, which contains the largest height because of our previous sort.

    Keep first record in 'Sort by'

The final data set looks like this:

Final dataset


These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.