From: Nathaniel Wooding on
And, here is one more. I did not use a count variable since the message indicates that there will always be two tests.

data have;
input SUBJID $ TEST $ VALUE1 VALUE2;
datalines;
A1 ONE 3 1
A1 TWO 2 2
A1 THREE 6 5
A2 ONE 4 3
A2 TWO 5 4
A2 THREE 8 9
;;;;
run;
Data Wanted;
set have;
by subjid;
if first.subjid then do;

Sum1 = 0;
sum2 = 0;
end;

if Test in ( 'ONE' , 'TWO' ) THEN DO;

Sum1 + Value1;
Sum2 + Value2;
end;
output;
if Test =: 'THREE' ;* do our arithmetic and output the new obs.;
Value1 = Sum1/2;
Value2 = Sum2/2;
Test = 'Mean';
output;
Drop sum: ;
proc print;
run;


Nat Wooding

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of W
Sent: Wednesday, February 17, 2010 2:33 PM
To: SAS-L(a)LISTSERV.UGA.EDU
Subject: means in long format

I have data in the following "long" format (obs=test, three tests per
subject)

SUBJID TEST VALUE1 VALUE2
A1 ONE 3 1
A1 TWO 2 2
A1 THREE 6 5
A2 ONE 4 3
A2 TWO 5 4
A2 THREE 8 9

I would like to add one observation per subject,
which would be the means of tests ONE and TWO, giving me the following:

SUBJID TEST VALUE1 VALUE2
A1 ONE 3 1
A1 TWO 2 2
A1 THREE 6 5
A1 MEAN 2.5 1.5
A2 ONE 4 3
A2 TWO 5 4
A2 THREE 8 9
A2 MEAN 4.5 3.5

I can do this easily when I convert the data into a "wide" format (obs=ID)
using the MEANS function, but I need to try & retain the "long" format.
I've tried a number of things, none of which works well, can anyone offer
any suggestions? (Some subjects may be missing some tests, & so there may
not be 3 complete observations per subject).

Thanks!
CONFIDENTIALITY NOTICE: This electronic message contains
information which may be legally confidential and or privileged and
does not in any case represent a firm ENERGY COMMODITY bid or offer
relating thereto which binds the sender without an additional
express written confirmation to that effect. The information is
intended solely for the individual or entity named above and access
by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying, distribution, or use of the
contents of this information is prohibited and may be unlawful. If
you have received this electronic transmission in error, please
reply immediately to the sender that you have received the message
in error, and delete it. Thank you.
From: William Whitworth on
A big thanks to all. Finally got some time to play around with these today.
First  |  Prev  | 
Pages: 1 2
Prev: New SAS product
Next: dumping memory