Date: Wed, 1 Oct 2008 14:01:15 -0700
Reply-To: "Richard A. DeVenezia" <rdevenezia@WILDBLUE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Richard A. DeVenezia" <rdevenezia@WILDBLUE.NET>
Organization: http://groups.google.com
Subject: Re: Summation by ID and date
Content-Type: text/plain; charset=ISO-8859-1
On Oct 1, 4:25 pm, Lauren <maillau...@gmail.com> wrote:
> Hi All -
>
> This seems like it should be a simple task but I'm having problems
> using the summation statement I would like to use (non-SQL). I want
> the summary of cost each id, by visit.
>
> I hoped the code could be something along the lines of this but I need
> the new visit date to start over with 0, sum those and then output the
> last visit total for each id.
...
>
> data new;
> set test;
> by id visit;
> if first.id then do;
> totalcost=0;
> end;
> totalcost+cost;
> if last.id then output;
> run;
Use first and last .visit instead of first and last .id.
When you do so, you will get one cost record per id visit
Note that it is quite simple to use a Proc SUMMARY to compute sums.
Additionally, if you are only reporting the sums, consider using Proc
REPORT or TABULATE.
Here are two different steps that do the same thing:
data new (drop=cost);
set test;
by id visit;
if first.visit then do;
totalcost=0;
end;
totalcost+cost;
if last.visit then output;
run;
data new2 (drop=cost);
totalcost=0;
do until (last.visit);
set test;
by id visit;
totalcost+cost;
end;
run;
--
Richard A. DeVenezia
http://www.devenezia.com