Hi, Karun You're doing a great job of reading through papers and picking up SAS. Here's a couple of methods that I like to use when I'm trying to figure out code. Try it yourself, and see what you think. First, from looking at the code, it looks like there's a dataset a that contains a variable Id that is some kind of "key", and a variable Var that is continuous, and it gets treated differently if it's missing. So I created the following SAS program: data a(drop=I); do i = 1 to 50; Id = floor(rand('uniform')*10); Var = rand('uniform') * 100; if rand('uniform') < .1 then call missing(Var); output; end; run; proc sort; by Id; run; You should be familiar with most of it. In terms of the unusual bits, the do...end will loop 50 times, and the output before the end writes a record, so it'll write 50 records to SAS dataset a; The rand('uniform') function will generate a random number uniformly distributed between 0 and 1. Multiplying it by 10 will uniformly distribute it between 0 and 10 (actually 9.9...), and the floor function will remove the decimal places, so Id will be a random integer between 0 and 9. Same idea for Var, but we'll make it between 0 and 100, and we won't remove the decimal places. The if statement will set Var to missing 10% of the time. And because there's a "by" statement in the code to be examined, we need to sort our data by the variable in the "by" statement. Here's the code under examination, with the changes I made: Data B ( Keep = Id Prod Sum Count Mean) ; putlog 'After Data statement ' _all_; Prod = 1 ; Do Count = 1 By 1 Until ( Last.Id ) ; putlog 'After Do statement ' _all_; Set A ; By Id ; putlog 'After Set statement ' _all_; If Missing (Var) Then Continue ; Mcount = Sum (Mcount, 1) ; Prod = Prod * Var ; Sum = Sum (Sum, Var) ; putlog 'Before End statement ' _all_; End ; Mean = Sum / Mcount ; putlog 'Before Run statement ' _all_; Run ; The only thing I did was to add five "putlog" statements in. These will print out the comment of where in the code we are, and then the _all_ clause prints out the values of all of the variables in the program. As a result, you get a log listing that pretty much lets you track the logic of the program. Play with it, and see what you think. Tom
... View more