Date: Fri, 7 May 2010 11:33:03 0500
ReplyTo: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SASL@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: Percentages
InReplyTo: <201005071604.o47FuxlE015711@malibu.cc.uga.edu>
ContentType: text/plain; charset=ISO88591
This might be the messiest answer I've ever given, but it's more of a
learning exercise for me really than anything :)
I use a hash object and iterator. This makes this really extendable. There
are much easier ways to do it with only 5 records [array!] but this would
work for 10000 subjects just as easily as 5.
data temp;
input Subject Totaldays;
datalines;
1 2
2 30
3 450
4 1461
5 2200
;;;;
run;
data want;
if _n_ = 1 then do;
declare hash h(dataset:"temp", ordered: 'yes');
declare hiter iter('h');
h.defineKey("subject");
h.defineData("totalDays","subject");
h.defineDone();
call missing(totalDays, subject);
end;
retain survived_initial;
survived_initial = h.num_items;
todel = 0;
do day = 1 to 2400;
if h.num_items > 1 then do;
do while (iter.next() = 0);
if todel then rc = h.remove(key:key);
if totalDays < day then do;
key = subject;
todel = 1;
end;
else todel = 0;
end;
end;
else do;
rc = h.find();
if totalDays < day then
rc = h.remove();
end;
survived = h.num_items;
surv_pct = survived/survived_initial;
keep day surv_pct; *remove this if you want to see all the gory
details;
output;
end;
run;
Joe
On Fri, May 7, 2010 at 11:04 AM, Brad Heins <hein0106@umn.edu> wrote:
> I am trying to find calculate a survival percentage for each day for
> certain
> subjects.
>
> My data is:
> Subject Totaldays
> 1 2
> 2 30
> 3 450
> 4 1461
> 5 2200
>
> I want to know what the percent survival is for each day up until 2400
> days,
> with my data. An example is what is the survival percentage for day 1, 2,
> 3,4, etc. up until 2400 days.
>
> The percent survival would be 100% for day 1, 100% for day 2, 80% for day
> 3,
> 80% for day 4 up to day 451.
>
> Maybe this is very simple and I am thinking about it too hard. If anyone
> could offer suggestions, it would be of great help.
>
> Thanks.
> Brad Heins
>
