From: Al on
Dear All:

These are the data sets i have ..


data lab;
input pat lab $ day;
cards;
1 BUN 1
1 BUN 23
1 BUN 30
1 BUN 46
1 BUN 56


run;
data ae;
input pat seq day_ae daysp;
cards;
1 1 19 25
1 2 29 .
1 3 40 45
1 4 20 29
1 5 50 52
run;


This is the output i am trying to get ..


Pat Seq Day23 Day30 Day46 Day56
1 1 x x
1 2 x x x
1 3 x x
1 4 x x
1 5 x


This is what I am trying to do .. I am trying to create a dataset
with
columns Day1 Day23 Day20 Day46 Day56 (The names of these columns are
the values of Day column in Lab data) and under these columns I
should be able to have the values of Day_ae and Daysp from AE data
in such a
way that


1<Day_AE<=23 must fall under Day 23 column and x must be assinged
under Day 23 column
and should be going across the rest of the columns if daysp is
missing
and if daysp is not missing x must be placed under the range of
columns ..


Hope this is clear..


Thanks in advance
Al
From: Reeza on
The following doesn't make sense to me.


> 1<Day_AE<=23  must fall under Day 23 column and x must be assinged
> under Day 23 column
> and should be going across the rest of the columns if daysp is
> missing
> and if daysp is not missing x must be placed under the range of
> columns ..


Here's code that does some of what you'd like.
Cheers,
Reeza

data lab;
input pat lab $ day;
cards;
1 BUN 1
1 BUN 23
1 BUN 30
1 BUN 46
1 BUN 56


run;
data ae;
input pat seq day_ae daysp;
cards;
1 1 19 25
1 2 29 .
1 3 40 45
1 4 20 29
1 5 50 52
run;

proc sql;
create table temp1 as
select a.*, b.day
from ae a
cross join lab b
order by pat, seq, day;
quit;

data temp2;
set temp1;
by seq;
if first.seq and day_ae<= day then category="X";
if day_ae <= day and day_ae > lag1(day) then category="X";
if day_ae <= day and daysp=. then category="X";
run;

proc transpose data=temp2(drop= day_ae daysp) prefix=day_ out=output;
by pat seq;
variable category;
id day;
run;
From: Al on
On Jun 16, 1:29 pm, Reeza <fkhurs...(a)hotmail.com> wrote:
> The following doesn't make sense to me.
>
> > 1<Day_AE<=23  must fall under Day 23 column and x must be assinged
> > under Day 23 column
> > and should be going across the rest of the columns if daysp is
> > missing
> > and if daysp is not missing x must be placed under the range of
> > columns ..
>
> Here's code that does some of what you'd like.
> Cheers,
> Reeza
>
> data lab;
>    input pat lab $ day;
>    cards;
> 1 BUN 1
> 1 BUN 23
> 1 BUN 30
> 1 BUN 46
> 1 BUN 56
>
> run;
> data ae;
>    input pat seq day_ae daysp;
>    cards;
> 1 1 19 25
> 1 2 29 .
> 1 3 40 45
> 1 4 20 29
> 1 5 50 52
> run;
>
> proc sql;
>         create table temp1 as
>         select a.*, b.day
>         from ae a
>         cross join lab b
>         order by pat, seq, day;
> quit;
>
> data temp2;
>         set temp1;
>         by seq;
>         if first.seq and day_ae<= day then category="X";
>         if day_ae <= day and day_ae > lag1(day) then category="X";
>         if day_ae <= day and daysp=. then category="X";
> run;
>
> proc transpose data=temp2(drop= day_ae daysp) prefix=day_ out=output;
> by pat seq;
> variable category;
> id day;
> run;


Thanks but i am also looking for an X if daysp exsits
for example
for pat = 1 ,seq = 1 ,daysp = 25 there should be an x under day 30
column and should stop propagating then on ..
hope i am clear .. please see the desired output in the earlier post

Thanks for your time
Al
From: Reeza on
On Jun 16, 11:39 am, Al <ali6...(a)gmail.com> wrote:
> On Jun 16, 1:29 pm, Reeza <fkhurs...(a)hotmail.com> wrote:
>
>
>
>
>
> > The following doesn't make sense to me.
>
> > > 1<Day_AE<=23  must fall under Day 23 column and x must be assinged
> > > under Day 23 column
> > > and should be going across the rest of the columns if daysp is
> > > missing
> > > and if daysp is not missing x must be placed under the range of
> > > columns ..
>
> > Here's code that does some of what you'd like.
> > Cheers,
> > Reeza
>
> > data lab;
> >    input pat lab $ day;
> >    cards;
> > 1 BUN 1
> > 1 BUN 23
> > 1 BUN 30
> > 1 BUN 46
> > 1 BUN 56
>
> > run;
> > data ae;
> >    input pat seq day_ae daysp;
> >    cards;
> > 1 1 19 25
> > 1 2 29 .
> > 1 3 40 45
> > 1 4 20 29
> > 1 5 50 52
> > run;
>
> > proc sql;
> >         create table temp1 as
> >         select a.*, b.day
> >         from ae a
> >         cross join lab b
> >         order by pat, seq, day;
> > quit;
>
> > data temp2;
> >         set temp1;
> >         by seq;
> >         if first.seq and day_ae<= day then category="X";
> >         if day_ae <= day and day_ae > lag1(day) then category="X";
> >         if day_ae <= day and daysp=. then category="X";
> > run;
>
> > proc transpose data=temp2(drop= day_ae daysp) prefix=day_ out=output;
> > by pat seq;
> > variable category;
> > id day;
> > run;
>
> Thanks but i am also looking for an X if daysp exsits
> for example
> for pat = 1 ,seq  = 1  ,daysp = 25 there should be an x under day 30
> column and should stop propagating then on ..
> hope i am clear .. please see the desired output in the earlier post
>
> Thanks for your time
> Al

You can add an if statement to the data temp2 statement to code for
this factor.

Something similar to the day_ae logic, but with day_sp instead.

HTH,
Reeza
From: Ya on
On Jun 16, 11:39 am, Al <ali6...(a)gmail.com> wrote:
> On Jun 16, 1:29 pm, Reeza <fkhurs...(a)hotmail.com> wrote:
>
>
>
>
>
> > The following doesn't make sense to me.
>
> > > 1<Day_AE<=23  must fall under Day 23 column and x must be assinged
> > > under Day 23 column
> > > and should be going across the rest of the columns if daysp is
> > > missing
> > > and if daysp is not missing x must be placed under the range of
> > > columns ..
>
> > Here's code that does some of what you'd like.
> > Cheers,
> > Reeza
>
> > data lab;
> >    input pat lab $ day;
> >    cards;
> > 1 BUN 1
> > 1 BUN 23
> > 1 BUN 30
> > 1 BUN 46
> > 1 BUN 56
>
> > run;
> > data ae;
> >    input pat seq day_ae daysp;
> >    cards;
> > 1 1 19 25
> > 1 2 29 .
> > 1 3 40 45
> > 1 4 20 29
> > 1 5 50 52
> > run;
>
> > proc sql;
> >         create table temp1 as
> >         select a.*, b.day
> >         from ae a
> >         cross join lab b
> >         order by pat, seq, day;
> > quit;
>
> > data temp2;
> >         set temp1;
> >         by seq;
> >         if first.seq and day_ae<= day then category="X";
> >         if day_ae <= day and day_ae > lag1(day) then category="X";
> >         if day_ae <= day and daysp=. then category="X";
> > run;
>
> > proc transpose data=temp2(drop= day_ae daysp) prefix=day_ out=output;
> > by pat seq;
> > variable category;
> > id day;
> > run;
>
> Thanks but i am also looking for an X if daysp exsits
> for example
> for pat = 1 ,seq  = 1  ,daysp = 25 there should be an x under day 30
> column and should stop propagating then on ..
> hope i am clear .. please see the desired output in the earlier post
>
> Thanks for your time
> Al- Hide quoted text -
>
> - Show quoted text -

A little modification to my code 3 days ago will work for the new
scenario:

data ae;
set ae (rename=(day_ae=dayst));
if daysp=. then daysp=58;
do day_ae=dayst to daysp;
output;
end;
keep pat seq day_ae;
run;

proc sort data=ae;
by pat descending day_ae;
run;


data lab;
set lab;
day_ae=day;
run;


proc sort data=lab;
by pat descending day_ae;
run;


data labae;
merge lab ae(in=b_);
retain labday;
by pat descending day_ae;
if first.pat then labday=.;
if ^missing(day) then labday=day;
else day=labday;
ae='x';
if b_;
run;


proc sort data=labae nodupkey;
by pat seq day;
run;


proc transpose data=labae out=tran (drop=_name_) prefix=Day;
by pat seq;
var ae;
id labday;
run;


proc print;
run;

pat seq Day23 Day30 Day46 Day56

1 1 x x
1 2 x x x
1 3 x
1 4 x x
1 5 x


BTW,

seq=3 should only fall in the day 46 bucket, since both 40-45 < 46.
 |  Next  |  Last
Pages: 1 2
Prev: Change from Baseline .
Next: do while