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 (January 2004, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 28 Jan 2004 14:26:27 GMT
Reply-To:     julierog@ix.netcom.com
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Roger Lustig <trovato@VERIZON.NET>
Subject:      Re: count & count(distinct)
Content-Type: text/plain; charset=us-ascii; format=flowed

Dear David: You've already seen the simple solution--PROC SQL. Here's a slightly more subtle one, which assumes that the input file is sorted by NAME and VALUE, but which runs like the wind.

data counts (drop=value); count=0; count_distinct=0; do until (last.name); set indata(keep=name value); by name value; count + 1; if first.value then count_distinct + 1; end; run;

By the way, when you can explain *why* this works, and what each statement does, you will no longer be a newbie to SAS.

Best, Roger

David Chang wrote:

> Hi, I am a newbie to SAS, and I am wondering whether SAS can do something > like sql's count and count(distinct) against SAS data sets. Here is an > example of what I am trying to do: > > Input data set: indata > name value > ==== ==== > john 4 > john 3 > tom 2 > tom 2 > tom 2 > > output data set: outdata > name count count_distinct > ==== ==== ========== > john 2 2 > tom 3 1 > > > Could anyone help me with this? A sample code would be greatly appreciated > !!! > > Regards, > > David > >


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