LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 2009, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 20 Apr 2009 11:39:59 -0500
Reply-To:   "./ ADD NAME=Data _null_;" <iebupdte@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "./ ADD NAME=Data _null_;" <iebupdte@GMAIL.COM>
Subject:   Re: remove the lowest 2 scores and avg on the rest
Comments:   To: Chang Chung <chang_y_chung@hotmail.com>
In-Reply-To:   <200904201559.n3KFXNM0024466@malibu.cc.uga.edu>
Content-Type:   text/plain; charset=ISO-8859-1

Hi Chang,

I get errors when I run this in V9.1.3 has the ARRANAME[*] specification changed in V9.2.

Also, in my limited experience I've found it most efficient to calculate the ADDRs just once instead of calling ADDR() on each iteration.

_null_;

83 /*- Hide quoted text -*/ 584 call sortn(of t[*]); ERROR: The ARRAYNAME[*] specification requires a variable based array. 585 call missing(t[1], t[2]); 586 /* calc n and mean */ 587 n = n(of t[*]); ERROR: The ARRAYNAME[*] specification requires a variable based array. 588 mean = mean(of t[*]); ERROR: The ARRAYNAME[*] specification requires a variable based array. 589 run;

On 4/20/09, Chang Chung <chang_y_chung@hotmail.com> wrote: > On Mon, 20 Apr 2009 10:40:48 -0500, Joe Matise <snoopy369@GMAIL.COM> wrote: > > >Maybe things have changed since I went to school, but a missing value for > a > >test score was a 'zero' back in the day... :) I'd either transform the > >missings to zero (if you have actual missing in the data) or do sum(of > >q3-q5)/3 ... > > > hi, Joe, > > in terms of data processing, a missing and a zero are totally different > things. Maybe teachers back then didn't have the sophisticated software > system like sas to make such a fine distinction. :-) > > by the way, I hard-coded "5" all over the place and made one mistake(guess > where?). that's not good. here is a parameterized and corrected one. :-) > > cheers, > chang > > /* test data. dot means the quiz missed. */ > data one; > input name $ q1-q5; > cards; > Alex 1 2 3 4 5 > Betty 2 2 . 4 4 > Clare 5 4 . . . > David 5 4 3 2 1 > ; > run; > > /* calculate mean quiz scores based on the > number of quizes taken, after dropping > two lowest scores. missing is considered > as the lowest score. */ > %let maxq = 5; /* change this to 12 if you have q1-q12 */ > %let mlen = %eval(&maxq. * 8); > data two; > set one; > /* make a copy */ > array q[1:&maxq.] 8 q1-q&maxq.; > array t[1:&maxq.] 8 _temporary_; > call poke(put(peekc(addr(q[1]),&mlen.),$&mlen..),addr(t[1]),&mlen.); > /* remove lowest two */ > call sortn(of t[*]); > call missing(t[1], t[2]); > /* calc n and mean */ > n = n(of t[*]); > mean = mean(of t[*]); > run; > > /* report */ > proc print data=two noobs; > run; > /* on lst > name q1 q2 q3 q4 q5 n mean > > Alex 1 2 3 4 5 3 4.00000 > Betty 2 2 . 4 4 3 3.33333 > Clare 5 4 . . . 2 4.50000 > David 5 4 3 2 1 3 4.00000 > */ >


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