Date: Wed, 21 Apr 2010 09:35:37 -0700
Reply-To: mlhoward@avalon.net
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mary <mlhoward@AVALON.NET>
Subject: Re: Filling in Gaps?
Content-Type: text/plain; charset="UTF-8"
Gerhard,
Thanks very much- these are excellent ideas to think about below, and the real issue is more complicated (adherence).
Sorry about the "want" data not being too good-maybe I'm trying to simulate the actual consumer in my "wanted" data, where they sometimes drop a pill in the sink and thus don't really have an extra on hand :-)
-Mary
--- gerhard.hellriegel@T-ONLINE.DE wrote:
From: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Filling in Gaps?
Date: Wed, 21 Apr 2010 12:19:50 -0400
you should define a array of days, something like
array pill(*) day1-day10;
then you can scroll through the array and add the extra pills in a pill-
container. If you detect a missing day, take a pill from container.
container=0;
do i=1 to dim(pill);
if pill(i)>1 then container = sum(container, pill(i)-1);
if i>1 and pill(i)=. then do;
if container>0 then do;
pill(i)=1;
container=container-1;
end;
end;
end;
what is not clear: what happens if there are gaps at start and extra pills
later?
. . 1 2 2 1 1 1
Result?
1 1 1 1 1 1 1 1 ?
Or you need pills (gaps) which come later (container is not full enough).
In that case you might scroll 2 times through the days. First time for
collecting pills, second for distributing them.
Other question is: what if there are not all pills needed? (at the end the
container has still extra-pills). Or what is if you don't have empty days,
still fill the container?
If the container contains pills at the end, I think it depends on the kind
of pills if you can throw them away....
2 1 1 1 1 1 1 1 1 1
result?
1 1 1 1 1 1 1 1 1 1 and one left?
or
1 1 1 1 1 1 1 1 1 2
or ???
Gerhard
On Wed, 21 Apr 2010 09:10:58 -0700, Mary <mlhoward@AVALON.NET> wrote:
>Hi,
>
>I've got a data set like this:
>
>data test2;
>infile cards missover;
>input id day1 day2 day3 day4 day5 day6 day7 day8 day9 day10;
>cards;
>001 1 1 1 1 2 2 . . . . 1 1
>002 2 2 2 . 1 . . . . . 1 .
>;
>run;
>
>These are the number of pills someone has on hand each day. What I want
is to fill in the gaps with the extra pills on hand, so I want a result
like this:
>
>001 1 1 1 1 1 1 1 1 . . 1 1
>002 1 1 1 1 1 1 . . . . 1 .
>
>Ideas would be appreciated; I'd like to keep this wide rather than
transpose it long if possible.
>
>-Mary