Date: Wed, 24 May 2006 10:02:25 -0400
Reply-To: "data _null_;" <datanull@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "data _null_;" <datanull@GMAIL.COM>
Subject: Re: proc means question example
In-Reply-To: <18e2c9740605240652w194df884r2660f87da7ae187e@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
proc summary data=work.scores nway missing;
class patient visit;
output out=work.scores2(drop=_type_ _freq_)
idgroup(min(hour) out[1](score)=firstScore)
idgroup(max(hour) out[1](score)=LastScore)
;
run;
On 5/24/06, jakeboot@gmail.com <jakeboot@gmail.com> wrote:
> I am trying to get the first and last score by visit using proc means
> vs. a datastep to output first. and last. then a transpose. I'm not sure
> if this can be done with proc means, by if so, then I don't have the correct
> syntax. I've tried searching on-line, but cannot find examples of what I
> want to
> do. From the data below, for each patient, and each visit, I want the first
> and last
> score.
> So for patient '0001' I want visit 1, first_score 5, last_score 2,
> '0001' visit 2, first_score 4, last_score 1
>
> & for patient '2000' I want visit 1, first_score 2, last_score 1,
> visit 2, first_score 3, last_score 1
>
> Is this possible with proc means? --if so, can anyone educate me
> on the syntax or point to some documentation?
>
> As I said before a datastep with a by for first. and last., then a transpose
> works, but it would be nice to do this in one step with proc means.
>
> data scores;
> length patient $4;
> format visit 3. hour time5. score 4.;
> patient='0001'; visit=1; hour='08:00't; score=5; output;
> patient='0001'; visit=1; hour='09:00't; score=3; output;
> patient='0001'; visit=1; hour='10:00't; score=3; output;
> patient='0001'; visit=1; hour='11:00't; score=2; output;
>
> patient='0001'; visit=2; hour='08:30't; score=4; output;
> patient='0001'; visit=2; hour='09:30't; score=3; output;
> patient='0001'; visit=2; hour='10:30't; score=2; output;
> patient='0001'; visit=2; hour='11:30't; score=1; output;
>
> patient='2002'; visit=1; hour='08:00't; score=2; output;
> patient='2002'; visit=1; hour='09:00't; score=3; output;
> patient='2002'; visit=1; hour='10:00't; score=2; output;
> patient='2002'; visit=1; hour='11:00't; score=1; output;
>
> patient='2002'; visit=2; hour='08:30't; score=3; output;
> patient='2002'; visit=2; hour='09:30't; score=3; output;
> patient='2002'; visit=2; hour='10:30't; score=3; output;
> patient='2002'; visit=2; hour='11:30't; score=1; output;
> run;
>
>
> proc sort data=scores;
> by patient visit hour;
> run;
>
> proc means data=scores noprint nway;
> var score;
> class patient visit;
> output out=_stats_ (drop=_freq_)
> /* min=f_visit
> max=l_visit*/
> minid(visit(score))=first_score
> maxid(visit(score))=last_score
> run;
>
> options byline;
> proc print data=scores;
> by patient visit;
> var hour score;
> run;
>
>
> proc print data=_stats_;
> run;
>
> Thanks, for you help!
>
>
> --
> Jake
> ---------------------
> Change the way you look at things, and the things you look at will change.
> Dr. Dyer
>
|