Download presentation
Presentation is loading. Please wait.
Published byLorenzo da Mota Modified over 5 years ago
1
Dr. Arthur Tabachneck Director, Data Management
Look Both Ways Dr. Arthur Tabachneck Director, Data Management Note: program stolen from a SASOPEDIA article by Howard Schreier
2
suppose you had the following data:
data have; input ID $ Measure; cards; A 11 A 12 A 13 A 14 B 21 B 22 B 23 ;
3
and you needed to have the following table:
data need; input ID $ Measure Next_Measure Last_Measure; cards; A A A A B B B ;
4
that is, with the following assignments made:
ID Measure Next_Measure Last_Measure A A A A B B B
5
that is, with the following assignments made:
ID Measure Next_Measure Last_Measure A A A A B B B
6
that is, with the following assignments made:
ID Measure Next_Measure Last_Measure A A A A B B B
7
a data step solution data need; set have; by ID;
set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
8
Why it works: Under the hood-Iteration #1:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ A PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
9
Why it works: Under the hood-Iteration #1:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ A PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
10
Why it works: Under the hood-Iteration #1:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ A PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
11
Why it works: Under the hood-Iteration #2:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ A PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
12
Why it works: Under the hood-Iteration #2:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ A PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
13
Why it works: Under the hood-Iteration #2:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ A PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
14
Why it works: Under the hood-Iteration #3:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ A PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
15
Why it works: Under the hood-Iteration #3:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ A PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
16
Why it works: Under the hood-Iteration #3:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ A PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
17
Why it works: Under the hood-Iteration #4:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ A PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
18
Why it works: Under the hood-Iteration #4:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ A PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
19
Why it works: Under the hood-Iteration #4:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ A PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
20
Why it works: Under the hood-Iteration #5:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ B PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
21
Why it works: Under the hood-Iteration #5:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ B PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
22
Why it works: Under the hood-Iteration #5:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ B PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
23
Why it works: Under the hood-Iteration #6:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ B PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
24
Why it works: Under the hood-Iteration #6:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ B PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
25
Why it works: Under the hood-Iteration #6:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ B PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
26
Why it works: Under the hood-Iteration #7:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ B PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
27
Why it works: Under the hood-Iteration #7:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ B PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
28
Why it works: Under the hood-Iteration #7:
ID Measure FIRST.ID LAST.ID Next_Measure Last_Measure _ERROR_ _N_ B PDV ID Measure A A A A B B B data need; set have; by ID; PutLog _all_ ; set have ( firstobs = 2 keep = Measure rename = (Measure = Next_Measure) ) have ( obs = 1 drop = _all_); Last_Measure = ifn( first.ID, (.), lag(Measure) ); Next_Measure = ifn( last.ID, (.), Next_Measure ); run;
29
ending up with the following table
ID Measure Next_Measure Last_Measure A A A A B B B
30
Questions? Your comments and questions are valued and encouraged.
Contact the author: Dr. Arthur Tabachneck Director, Data Management Insurance Bureau of Canada Toronto, Ontario L3T 5K9
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.