以sas

时间:2016-01-13 18:42:42

标签: sas

data bob;
input subjid test$ lbdy flag1$;
datalines;

101 alt 1 e
101 alt 2 .
101 alt 3 e
101 alt 4 e
101 ast 1 e
101 ast 3 e
101 ast 4 .
101 ast 5 e
102 alt 1 e
102 alt 2 .
102 alt 3 e
102 alt 4 e
102 ast 1 e
102 ast 2 .
102 ast 3 e
102 ast 4 .
102 ast 5 e
102 ast 6 e
;
run;

我需要找到连续值

我的预期输出是

             count
101 alt 1 e   1
101 alt 2 .   
101 alt 3 e   2
101 alt 4 e   2
101 ast 1 e   2
101 ast 3 e   2
101 ast 4 .
101 ast 5 e   1 
102 alt 1 e   4
102 alt 2 e   4
102 alt 3 e   4
102 alt 4 e   4
102 ast 1 e   1
102 ast 2 .   
102 ast 3 e   1
102 ast 4 .
102 ast 5 e   2
102 ast 6 e   2

提前致谢

1 个答案:

答案 0 :(得分:1)

我认为这就是你想要的。很难从神秘的描述中知道。

data bob;
input subjid test$ lbdy flag1$;
datalines;
101 alt 1 e
101 alt 2 .
101 alt 3 e
101 alt 4 e
101 ast 1 e
101 ast 3 e
101 ast 4 .
101 ast 5 e
102 alt 1 e
102 alt 2 e
102 alt 3 e
102 alt 4 e
102 ast 1 e
102 ast 2 .
102 ast 3 e
102 ast 4 .
102 ast 5 e
102 ast 6 e
;;;;
   run;
proc sort data=bob;
   by subjid test lbdy;
   run;
proc print;
   run;
data dob2;
   do _n_=1 by 1 until(last.flag1);
      set bob;
      by subjid test flag1 notsorted;
      end;
   if not missing(flag1) then count = _n_;
   do _n_ = 1 to _n_;
      set bob;
      output;
      end;
   run;
proc print;
   run;

enter image description here