I want to change the following data one into two data. My colleage and I
could not figure out how to do it in SAS.
one:
id status day
1 1 0
1 1 5
1 1 10
1 2 15
1 3 20
1 3 25
1 2 30
1 4 35
two:
id pre_status end_status pre_day end_day
1 1 2 0 15
1 2 3 15 20
1 3 2 20 30
1 2 4 30 35
Thanks for help.
p********a 发帖数: 5352
2
data a;
input id status day;
datalines;
1 1 0
1 1 5
1 1 10
1 2 15
1 3 20
1 3 25
1 2 30
1 4 35
run;
data b(keep=ID Pre_status End_status Pre_day End_day);
retain Pre_status End_status Pre_day End_day;
set a;
if _N_=1 then do; Pre_status=status; Pre_day=day;end;
if status ne pre_status then do;End_status=Status;End_day=day;output; Pre_
status=status; Pre_day=day; end;
run;
proc print;
run;