Example 8.12 Collapsing Observations within a BY Group into a Single Observation

Goal

Rearrange a data set by changing selected variables in a group of observations to a group of variables in one observation. Reshape data by collapsing observations within a BY group into a single observation in order to simplify data analysis and report generation.

The example uses the same input data set as Example 8.9.

Example Features

Featured StepDATA step
Featured Step Options and StatementsBY statement

FIRST.variable and LAST.variable temporary variables

OUTPUT statement
Related TechniquePROC TRANSPOSE, PREFIX= option, BY, ID, RETAIN, and VAR statements DATA step, match-merging by value and merging a data set with itself

Input Data Set

Data set WEIGHT_BMI ...

Get Combining and Modifying SAS® Data Sets: Examples Second Edition now with O’Reilly online learning.

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