Date: Tue, 27 Jan 2009 09:19:12 -0500
Reply-To: "Howard Schreier <hs AT dc-sug DOT org>"
<schreier.junk.mail@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Howard Schreier <hs AT dc-sug DOT org>"
<schreier.junk.mail@GMAIL.COM>
Subject: Re: Calculate the difference between values across all records
On Tue, 27 Jan 2009 01:35:07 -0800, Keith W. Larson
<keith_w_larson@YAHOO.COM> wrote:
>Dear SAS list,
>
>I have some weather data for 145 locations across Europe. I would like to
calculate the difference between the mean annual temperature at each
location. I am not interested in a matrix, just three columns, Location_A,
Location_B, and Temp_Difference. I have included some sample code and what I
anticipate the output to look like.
>
>Thank you for your help once again.
>Keith
>
>data test;
>input location mean_temp;
>cards;
>
>Paris 30
>London 24
>Stockholm 20
>
>run;
>
>The results might look like this:
>
>Paris Paris 0
>Paris London 6
>Paris Stockholm 10
>London Paris 6
>London London 0
>London Stockholm 4
>Stockholm Paris 10
>Stockholm London 4
>Stockholm Stockholm 0
Code:
proc sql;
options formchar=' ';
select catx( ' '
, a.location
, b.location
,abs(a.mean_temp - b.mean_temp)
)
from test as a cross join test as b
order by a.mean_temp desc
, b.mean_temp desc
;
Result:
Paris Paris 0
Paris London 6
Paris Stockholm 10
London Paris 6
London London 0
London Stockholm 4
Stockholm Paris 10
Stockholm London 4
Stockholm Stockholm 0
|