Date: Thu, 29 Aug 2002 18:49:51 -0400
Reply-To: "Dorfman, Paul" <Paul.Dorfman@BCBSFL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Dorfman, Paul" <Paul.Dorfman@BCBSFL.COM>
Subject: Re: transpose
Content-Type: text/plain; charset=iso-8859-1
Asheber,
Floyd has shown you how to print the result you want easily using the Freq
proc. If you need an actual file, you can try this (I assume the file is
grouped by code):
data b (keep = score_: total) ;
array s score_1 - score_3 ;
do until (last.code) ;
set a (rename=(score=_i_)) ;
by code notsorted ;
s = sum (s, 1) ;
end ;
total = sum (of s(*)) ;
run ;
If in a given code, there is no record with one of the three scores, the
output will contain a missing value, like
score_1 score_2 score_3 total
---------------------------------------
1 2 1 4
. 1 2 3
. 2 . 2
1 . 1 2
1 . . 1
---------------------------------------
If you actually need zeroes, insert
do over s ;
s = 0 ;
end ;
before the DoW-loop.
Kind regards,
====================
Paul M. Dorfman
Jacksonville, FL
====================
> -----Original Message-----
> From: Asheber Sewalem [mailto:sewalem@CDN.CA]
> Sent: Thursday, August 29, 2002 3:33 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: transpose
>
>
> Hi all,
>
> I would appreciate if you give me an efficient way of doing the
> following data set.(i.e., the total number of observation in each code
> and by score). I used proc transpose and it did not give me
> the desired
> output, may be I missed something. Please have a look at below the
> desired output.
>
>
> data a;
> input id code score;
> cards
> ;
> 161 12 3
> 139 12 2
> 120 12 1
> 163 12 2
> 144 10 3
> 143 10 3
> 135 10 2
> 132 11 2
> 147 11 2
> 143 13 3
> 170 13 1
> 155 14 1
> ;
>
> The desired output should be,
>
> Obs code score_1 score_2 score_3 total
> 1 10 0 1 2 3
> 2 11 0 2 0 2
> 3 12 1 2 1 4
> 4 13 1 0 1 2
> 5 14 1 0 0 1
>
> Asheber
>
Blue Cross Blue Shield of Florida, Inc., and its subsidiary and
affiliate companies are not responsible for errors or omissions in this e-mail message. Any personal comments made in this e-mail do not reflect the views of Blue Cross Blue Shield of Florida, Inc.
|