Previous PageNext Page

Creating Several Observations from One Observation
Suppose the data set CLINIC contains patient IDs and up to three diagnostic codes, in addition to other variables. If a patient has more than three codes, a new record appears. We want a new data set, DIAGS, to contain one observation for each diagnostic code.
Data clinic;
infile datalines missover;
input patient (diag1-diag3) ( : $5.) ;
datalines;
1001 123.23 443.22 114.2
1001 200.
1002 V70
1103 123.23 443.22
;

Data diags;
set clinic;
by patient;
array diags{*} diag1-diag3;
do i=1 to 3;

drop i diag1-diag3;

proc print data=diags;
title "Diagnoses";
run;

Output:
Diagnoses
Obs patient diagcode

1 1001 123.2
2 1001 443.2
3 1001 114.2
4 1001 200.
5 1002 V70
6 1103 123.2
7 1103 443.2

Previous PageTable Of ContentsNext Page