LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (February 2008, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 7 Feb 2008 16:06:51 -0500
Reply-To:     Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Subject:      Re: Proc summary equivalent Hash object
In-Reply-To:  <200802072047.m17HA5vN001517@mailgw.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1

On Feb 7, 2008 3:47 PM, SUBSCRIBE SAS-L Anonymous <hari.sas.j@gmail.com> wrote:

> Thanks All for your replies: > > I tried this one before, However I still did not get the desired output: > > Here is the code: > > data input ; > input k1 $ k2 $ num num1; > datalines; > m a 1 2 > m b 2 4 > c a 3 5 > c d 2 6 > g a 5 7 > ; > run ; > > > proc summary data = input nway ; > class k1 ; > var num num1; > output out = summ_sum (drop = _:) sum=; > run ; > > > > data _null_ ; > > if 0 then set input ; > > dcl hash hh (hashexp:16, ordered: 'a') ; > hh.definekey ('k1' ) ; > hh.definedata ('k1','sum','sum1') ; > hh.definedone () ; > > do until (eof) ; > set input end = eof ; > if hh.find () ne 0 then do; > sum = 0 ; > sum1 = 0; > sum ++ num ; > sum1 + num1 ; > hh.replace () ; > end; > end ; > > > rc = hh.output (dataset: 'hash_sum') ; > > run ; > > Here is the output: > > ******* summ_sum *********** > k1 num num1 > c 5 11 > g 5 7 > m 3 6 > > ******* hash_sum ************ > k1 num num1 > c 3 5 > g 5 7 > m 1 2 >

Hi,

The end is placed at a wrong place.

try this:

data _null_ ;

if 0 then set input ;

dcl hash hh (hashexp:16, ordered: 'a') ; hh.definekey ('k1' ) ; hh.definedata ('k1','sum','sum1') ; hh.definedone () ;

do until (eof) ; set input end = eof ; if hh.find () ne 0 then do; sum = 0 ; sum1 = 0; end; sum ++ num ; sum1 + num1 ; hh.replace () ; end ;

rc = hh.output (dataset: 'hash_sum') ;

run ;


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