Date: Thu, 20 Oct 2011 16:57:48 -0400
Reply-To: Subhadra Srigiriraju <subhadrasri@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Subhadra Srigiriraju <subhadrasri@GMAIL.COM>
Subject: Re: Help with Cumulative Totals in Proc Report
In-Reply-To: <FA0550A1D186FF49BB0748CD711B17EDD90E13CC5D@SDPSMSX.QUALNET.ORG>
Content-Type: text/plain; charset=ISO-8859-1
Thanks a lot Haikuo and Ben for your responses. Haikuo's approach worked
perfectly! Thanks!
On Tue, Oct 18, 2011 at 2:34 PM, Bian, Haikuo <HBian@flqio.sdps.org> wrote:
> Hi Sri,
>
> Since report items are not retained, you would need a non-report temporary
> variable to retain the value:
>
> proc report data=sashelp.class nowd headline out=tst1;
> column sex age height weight age=no col_a;
> define sex / group;
> define height / analysis mean;
> define no / analysis n "Count" format=comma12.0;
> compute col_a;
> temp1+height.mean*no;
> col_a=temp1;
> endcomp;
> run;
>
>
> HTH,
> Haikuo
>
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Sri
> Sent: Monday, October 17, 2011 10:05 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Help with Cumulative Totals in Proc Report
>
> Dear SAS users,
>
> I have a question on proc report and hoping that some one in the group
> would throw some light on my issue.
>
> Below is the SAS dataset i created using proc report. Right now, "col_a"
> is blank and the "Expected" column is what i want to display on my report.
>
> "Expected" is the cumulative count plus product of height and count.
> Kind of SumProduct function in Excel.
>
> Sex Age Height Weight Count col_a Expected
> F 119 60.5889 811 9 . 545.3001 -->
> height*count
> M 134 63.91 1089.5 10 . 1184.4001 --> 545.3001+
> ( height*count)
>
> Here is my SAS program:
>
> proc report data=sashelp.class nowd out=tst1;
> column sex age height weight age=no col_a;
> define sex / group;
> define height / analysis mean;
> define no / analysis n "Count" format=comma12.0;
> compute col_a;
> if _n_=1 then col_a=height.mean*no;
> else col_a=lag(col_a)+height.mean*no;
> endcomp;
> run;
>
> I tried to use lag function with "if" condition but it didn't work.
> Couldn't use Retain either. Any help would be much appreciated.
>
> I referred couple of SUGI Papers online but they have examples when the
> analysis variable has "Sum" instead of "Mean".
>
> Thanks
> Sri
> -----------------------------------------
> Email messages cannot be guaranteed to be secure or error-free as
> transmitted information can be intercepted, corrupted, lost,
> destroyed, arrive late or incomplete, or contain viruses. The
> Centers for Medicare & Medicaid Services therefore does not accept
> liability for any error or omissions in the contents of this
> message, which arise as a result of email transmission.
>
> CONFIDENTIALITY NOTICE: This communication, including any
> attachments, may contain confidential information and is intended
> only for the individual or entity to which it is addressed. Any
> review, dissemination, or copying of this communication by anyone
> other than the intended recipient is strictly prohibited. If you
> are not the intended recipient, please contact the sender by reply
> email and delete and destroy all copies of the original message.
>
--
\\ ~ ~ //
( @ @ )
==oOOo===oOOo==
Subhadra Srigiriraju
* If there are no stupid questions, then what kind of questions do stupid
people ask? Do they get smart just in time to ask questions? :) - Dilbert
Principle*
=======Oooo.=====
.oooO( )
( )) )
\ ( (_)
\_)
|