Date: Mon, 22 Jan 2007 10:04:05 -0500 Hari Nath "SAS(r) Discussion" Hari Nath means first. -- wonder if this is possible in a single datastep

Hi all, iam trying to get the means for only visit 1 and then trying to keep this in a same datastep.....can someone point me in right way... Many thanks hari

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> data test ; input pat \$ treat \$ visit var1 var2 ; cards ; 1000 A 1 100 90 1000 A 1 70 50 1000 A 1 30 50 1000 A 2 20 30 1000 A 2 50 60 1000 A 2 40 20 1000 A 3 50 30 1000 A 3 60 30 2000 B 1 80 90 2000 B 1 . . 2000 B 1 . . 2000 B 2 30 30 2000 B 2 40 60 2000 B 2 80 20 2000 B 3 30 30 2000 B 3 40 30 ; run ;

proc sort data=test ; by pat treat visit ; run ;

data test2 ; retain var1_b var2_b ; set test ; by pat treat visit ;

if visit=1 then do ;

if first.visit then do ; var1_b = 0 ; var2_b = 0 ; counter=0; end ; var1_b = sum(var1 + var1_b) ; var2_b = sum(var2 + var2_b) ; counter + 1 ;

if last.visit then do ; var1_b = round(var1_b / counter,.01) ; var2_b = round(var2_b / counter,.01) ; end ;

end ;

else if visit ^= 1 then do ; var1_b = var1 ; var2_b = var2 ; counter=0 ;

end ; /* if last.visit ne . then output ;*/ run ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

current output ;

pat treat visit var1 var2 var1b var2b

1000 A 1 100 90 100 90 1000 A 1 70 50 170 140 1000 A 1 30 50 66.67 63.33 1000 A 2 20 30 20 30 1000 A 2 50 60 50 60 1000 A 2 40 20 40 20 1000 A 3 50 30 50 30 1000 A 3 60 30 60 30 2000 B 1 80 90 80 90 2000 B 1 . . . . 2000 B 1 . . . . 2000 B 2 30 30 30 30 2000 B 2 40 60 40 60 2000 B 2 80 20 80 20 2000 B 3 30 30 30 30 2000 B 3 40 30 40 30

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

desired output ;

pat treat visit var1 var2 var1b var2b

1000 A 1 30 50 66.67 63.33 1000 A 2 20 30 20 30 1000 A 2 50 60 50 60 1000 A 2 40 20 40 20 1000 A 3 50 30 50 30 1000 A 3 60 30 60 30 2000 B 1 80 90 80 90 2000 B 2 30 30 30 30 2000 B 2 40 60 40 60 2000 B 2 80 20 80 20 2000 B 3 30 30 30 30 2000 B 3 40 30 40 30

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Back to: Top of message | Previous page | Main SAS-L page