Sample 26013: Carry non-missing values down a BY-Group
Use BY-Group processing, RETAIN, and conditional logic to carry non-missing values down a BY-Group.
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.
/* Create sample data */
data one;
input id $ x;
datalines;
a 1
a .
a 2
a 3
a .
a .
b .
b 2
b .
b 4
;
data two;
drop temp;
set one;
by id;
/* RETAIN the new variable */
retain temp;
/* Reset TEMP when the BY-Group changes */
if first.id then temp=.;
/* Assign TEMP when X is non-missing */
if x ne . then temp=x;
/* When X is missing, assign the retained value of TEMP into X */
else if x=. then x=temp;
run;
proc print data=one;
title 'Before';
run;
proc print data=two;
title 'After';
run;
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.
Before
Obs id x
1 a 1
2 a .
3 a 2
4 a 3
5 a .
6 a .
7 b .
8 b 2
9 b .
10 b 4
After
Obs id x
1 a 1
2 a 1
3 a 2
4 a 3
5 a 3
6 a 3
7 b .
8 b 2
9 b 2
10 b 4
Use BY-Group processing, RETAIN, and conditional logic to carry non-missing values down a BY-Group.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step Data Management ==> Manipulation and Transformation ==> BY-group processing
|
Date Modified: | 2007-11-14 09:49:07 |
Date Created: | 2006-01-27 15:24:13 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |