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 Step | DATA step |
Featured Step Options and Statements | BY statement
FIRST.variable and LAST.variable temporary variables OUTPUT statement |
Related Technique | PROC 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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.