Date: Wed, 8 Apr 2009 15:32:10 -0500
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: Percentages
In-Reply-To: <456B52C41B724C41B96561D7AD283E7DEFEBCF@mail.chpdm.umbc.edu>
Content-Type: text/plain; charset=ISO-8859-1
You were on the right track ...
proc sql;
create table next as
select *, var/sum(var) as varpct
from have
group by id
;
quit;
is all that's needed to be changed :)
-Joe
On Wed, Apr 8, 2009 at 3:23 PM, Jack Clark <jclark@hilltop.umbc.edu> wrote:
> Randy,
>
> I think you have to find the sum of VAR within each ID, then calculate
> the percent from there. Here is one possible solution.
>
> Someone with more SQL experience could probably offer a solution that
> incorporates the percent calculation in the SQL step.
>
>
> data have;
> input ID Cat Var;
> cards;
> 1 1 2010
> 1 2 3065
> 1 3 5467
> 1 4 8765
> 2 1 8733
> 2 2 300
> 2 3 467
> 2 4 67
> ;
> run;
>
> proc sql;
> create table next as
> select *, sum(var) as varsum
> from have
> group by id
> ;
> quit;
>
> data need;
> set next;
> per = var / varsum;
> run;
>
> proc print data = need;
> run;
>
>
> Jack
>
>
>
>
> Jack Clark
> Senior Research Analyst
> phone: 410-455-6256
> fax: 410-455-6850
> jclark@hilltop.umbc.edu
>
> University of Maryland, Baltimore County
> Sondheim Hall, 3rd Floor
> 1000 Hilltop Circle
> Baltimore, MD 21250
>
>
>
>
> Confidentiality Notice: This e-mail may contain information that is legally
> privileged and that is intended only for the use of the addressee(s) named
> above. If you are not the intended recipient, you are hereby notified that
> any disclosure, copying of this e-mail, distribution, or action taken in
> reliance on the contents of this e-mail and/or documents attributed to this
> e-mail is strictly prohibited. If you have received this information in
> error, please notify the sender immediately by phone and delete this entire
> e-mail. Thank you.-----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> Randy
> Sent: Wednesday, April 08, 2009 3:56 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Percentages
>
> Here is my data set
>
> ID Cat Var
> 1 1 25
> 1 2 35
> 1 3 30
> 1 4 10
> 2 1 18
> 2 2 22
> 2 3 60
> 2 4 0
>
> I want the percentages for each category for each ID. So the data set
> should be
>
> ID Cat Var Per
> 1 1 25 0.25
> 1 2 35 0.35
> 1 3 30 0.3
> 1 4 10 0.1
> 2 1 18 0.18
> 2 2 22 0.22
> 2 3 60 0.60
> 2 4 0 0
>
> Can someone please help.
> Thank You
> Randy
>
|