Date: Wed, 4 Jun 2003 22:33:22 -0700
Reply-To: "Huang, Ya" <yhuang@AMYLIN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Huang, Ya" <yhuang@AMYLIN.COM>
Subject: Re: One pass to find max and maxcnt using data step?
Content-Type: text/plain; charset="iso-8859-1"
Thanks Paul,
I thought about using temporary array, but gave up
because dos's value can be anything, decimal or integer,
it could be very hard to transform it to integer
so that it can be used as array index. Suppose
dos takes 0.001,0.1,1,10,100, to transform them all
into a integer, the factor need to be 1000, and the
array size would be 100,000, while only 5 cell of
this huge array will be really used for frequency
counting, it seems very low efficient.
Maybe I can use format, but it doesn't seem to worth it.
Kind regards,
Ya
-----Original Message-----
From: Paul Dorfman [mailto:paul_dorfman@HOTMAIL.COM]
Sent: Wednesday, June 04, 2003 10:01 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: One pass to find max and maxcnt using data step?
Ya,
Man, you must be pulling our sas-leg:
%let factor = 1000 ;
data squeezed ( keep = id max_dos max_cnt ) ;
array grp ( 0 : &factor ) _temporary_ ;
do _n_ = lbound (grp) to hbound (grp) ;
grp (_n_) = . ;
end ;
do until ( last.id ) ;
set xx ;
by id ;
grp (dos * &factor) ++ 1 ;
end ;
do _n_ = hbound (grp) by -1 until ( grp(_n_) ) ;
end ;
max_dos = _n_ / &factor ;
max_cnt = grp(_n_) ;
run ;
Kind regards,
---------------------------------
Paul M. Dorfman
Jacksonville, FL
---------------------------------
>From: "Huang, Ya" <yhuang@AMYLIN.COM>
>Reply-To: "Huang, Ya" <yhuang@AMYLIN.COM>
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: One pass to find max and maxcnt using data step?
>Date: Wed, 4 Jun 2003 15:47:00 -0700
>
>Hi there,
>
>data xx;
>input id dos;
>cards;
>1 0.1
>1 0.1
>1 0.01
>1 0.01
>1 0.01
>1 0.01
>1 0.3
>1 0.3
>1 0.3
>2 0.2
>2 0.2
>2 0.6
>2 0.05
>2 0.05
>2 0.05
>2 0.05
>2 0.6
>2 0.6
>2 0.6
>2 0.6
>2 0.6
>;
>
>For the above data, I need to find, for each id, the max of dos,
>and the number of dos at the max level, so the expected result
>is as below:
>
>id max_dos maxcnt
>1 0.3 3
>2 0.6 6
>
>It is very easy to get the max_dos, I just wonder if it is
>possible to get the count of max_dos in the same step?
>
>Any comments?
>
>Thanks
>
>Ya
_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail
|