Reading Hierarchical Files |
Creating One Observation per Detail
Record |
In order to create one observation per detail record, it is necessary
to distinguish between header and detail records. Having a field that identifies
the type of the record makes this task easier.
In the raw data file Census, shown below, H indicates a header record that contains a street address and P indicates a detail record that contains information about a person living at that address. |
Raw Data File
1---+----10---+----
H 321 S. MAIN ST
P MARY E 21 F
P WILLIAM M 23 M
P SUSAN K 3 F
H 324 S. MAIN ST
P THOMAS H 79 M
P WALTER S 46 M
P ALICE A 42 F
P MARYANN A 20 F
P JOHN S 16 M
H 325A S. MAIN ST
Let's see how you can create a data set that contains one observation for each person living at a specific address. |
SAS Data Set
Obs
Address
Name
Age
Gender
1
321 S. MAIN ST
MARY E
21
F
2
321 S. MAIN ST
WILLIAM M
23
M
3
321 S. MAIN ST
SUSAN K
3
F
4
324 S. MAIN ST
THOMAS H
79
M
5
324 S. MAIN ST
WALTER S
46
M
6
324 S. MAIN ST
ALICE A
42
F
7
324 S. MAIN ST
MARYANN A
20
F
8
324 S. MAIN ST
JOHN S
16
M
9
325A S. MAIN ST
JAMES L
34
M
10
325A S. MAIN S
T LIZA A
31
F
11
325B S. MAIN S
T MARGO K
27
F
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.