data have;
infile cards expandtabs;
input ID (week1 week2 week3 week4 week5 week6 week7 week8) ($);
datalines;
1 A A B B B A A A
2 B B B B B B B B
3 B B A A A A A A
4 A A A A B B B B
;
proc transpose data=have out=temp;
by id;
var week:;
run;
proc summary data=temp;
by id col1 notsorted;
output out=temp1 ;
run;
proc transpose data=temp1 out=temp2 prefix=seq;
by id;
var _freq_;
run;
data temp3;
set temp2;
total=n(of seq:);
drop _name_;
run;
data want;
merge have temp3;
by id;
run;
proc print;run;
... View more