```Date: Wed, 21 Jul 2004 03:07:22 GMT Reply-To: julierog@ix.netcom.com Sender: "SAS(r) Discussion" From: Roger Lustig Subject: Re: A simpler way? Content-Type: text/plain; charset=us-ascii; format=flowed Dear Pat: Don't know about "sophisticated", but how about "terse"? If all you want is the GPA at the end, how about: array grade (6) p1grnum p2grnum p3grnum p4grnum p5grnum p6grnum; do I=1 to 6; if grade(I) >=4 then do; total = sum(total,grade(I); counted=sum(counted,1); end; end; if counted > 0 then preqgpa = total / counted; drop counted total I; This has the advantage of being easy to modify in case, say, more than 6 grades are involved. Of course, further efficiency might come from naming the grade variables so that the number is at the end: array grade (6) pgrnum1-pgrnum6; If the variables are indeed named that way, you can even enumerate them implicitly: array pgrnum (6); If you need the recoded grades, you can do the following: array pg (6); do I=1 to 6; if grade(I) >=4 then do; pg(I) = grade(I)-4; total = sum(total,grade(I); counted=sum(counted,1); end; end; Note that you don't have to set the other recoded grades to missing--they're already that way. OK? Roger Pat Moore wrote: > I have variables p1grnum--p6grnum that each vary from 0-8. I wrote this > code: > > /*this makes grnums below 4 negative numbers*/ > p1g=p1grnum-4; > p2g=p2grnum-4; > p3g=p3grnum-4; > p4g=p4grnum-4; > p5g=p5grnum-4; > p6g=p6grnum-4; > /*this sets negative values of p1g-p6g to missing so non-letter grades are > not computed into the gpa*/ > if p1g<0 then p1g=.; > if p2g<0 then p2g=.; > if p3g<0 then p3g=.; > if p4g<0 then p4g=.; > if p5g<0 then p5g=.; > if p6g<0 then p6g=.; > /*this computes the grade point average with the modified values*/ > preqgpa=mean(p1g,p2g,p3g,p4g,p5g,p6g); > > Is there some more sophisticated way to do this? ```

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