<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Summing based on 2 Pairs (Airport Data) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summing-based-on-2-Pairs-Airport-Data/m-p/620413#M182303</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142314"&gt;@BCNAV&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You've had three good answer, yet none uses PROC SUMMARY, which I think of as the tool SAS intended to solve this problem. So, for completeness sake:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input depart $ dest $ ocu ;
  cards ;
cyyz  egll  500
cyvr  cyyz   10
egll  cyyz  500
;

data vneed/ view=vneed;
  set have;
  call sortc (depart,dest);
  length pair $9;
  pair=catx('-',depart,dest);
run;
proc summary data=vneed nway;
  class pair;
  var ocu;
  output out=want (drop=_type_ _freq_) sum=sumocu;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The nice thing about PROC SUMMARY is that it offers keywords that generate a lot of statistics in addition to SUM (e.g. mean, std, median, other percentiles, …).&amp;nbsp; And you could simultaneously do it not only for all pairs, but also for all DEPART values, and all DEST values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jan 2020 02:26:07 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2020-01-28T02:26:07Z</dc:date>
    <item>
      <title>Summing based on 2 Pairs (Airport Data)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-based-on-2-Pairs-Airport-Data/m-p/620327#M182257</link>
      <description>&lt;P&gt;I have some airport departure and destination data, along with charges.&amp;nbsp; Suppose I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;depart&amp;nbsp; &amp;nbsp; &amp;nbsp;dest&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; OCU&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;cyyz&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;egll&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 500&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;cyvr&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cyyz&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;egll&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cyyz&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 500&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like to do is to sum OCU by city pair, which is the concatenation of depart and dest, hopefully in the format of depart-dest (dash in between them).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The price is that reverse flights should be included as one...so above the final output dataset would be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;City_Pair&amp;nbsp; &amp;nbsp; &amp;nbsp;OCU&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;cyyz-egll&amp;nbsp; &amp;nbsp; &amp;nbsp;1000&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;cyvr-cyyz&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for any advice!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 20:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-based-on-2-Pairs-Airport-Data/m-p/620327#M182257</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2020-01-27T20:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Summing based on 2 Pairs (Airport Data)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-based-on-2-Pairs-Airport-Data/m-p/620331#M182261</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you mean something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input depart $ dest $ OCU;
cards;
cyyz       egll        500
cyvr       cyyz         10
egll       cyyz        500
;
run;
proc print;
run;

data have2 / view = have2;
  set have;
  array dd[*] depart dest;
  call sortc(of dd[*]);
  grp = catx("-", of dd[*]);
run;

proc sql;
  select grp, sum(ocu) as sumOcu
  from have2
  group by grp
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 20:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-based-on-2-Pairs-Airport-Data/m-p/620331#M182261</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-01-27T20:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Summing based on 2 Pairs (Airport Data)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-based-on-2-Pairs-Airport-Data/m-p/620390#M182292</link>
      <description>&lt;P&gt;As a single query:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select
	catx("-", a.depart, a.dest) as cityPair,
	sum(a.OCU, b.OCU) as OCU
from 
	have as a left join
	have as b on a.depart=b.dest and a.dest=b.depart
where b.depart &amp;lt; a.dest or b.depart is missing;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Jan 2020 23:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-based-on-2-Pairs-Airport-Data/m-p/620390#M182292</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-01-27T23:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: Summing based on 2 Pairs (Airport Data)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-based-on-2-Pairs-Airport-Data/m-p/620410#M182301</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142314"&gt;@BCNAV&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yet another variation - hash-based:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                                                                                                                                                                                                     
  input depart $ dest $ ocu ;                                                                                                                                                                                                                                   
  cards ;                                                                                                                                                                                                                                                       
cyyz  egll  500                                                                                                                                                                                                                                                 
cyvr  cyyz   10                                                                                                                                                                                                                                                 
egll  cyyz  500                                                                                                                                                                                                                                                 
;                                                                                                                                                                                                                                                               
data _null_ ;                                                                                                                                                                                                                                                   
  dcl hash h () ;                                                                                                                                                                                                                                               
  h.definekey  ("city_pair") ;                                                                                                                                                                                                                                  
  h.definedata ("city_pair", "ocu") ;                                                                                                                                                                                                                           
  h.definedone () ;                                                                                                                                                                                                                                             
  do until (z) ;                                                                                                                                                                                                                                                
    set have (rename=ocu=_ocu) end = z ;                                                                                                                                                                                                                        
    city_pair = put (catx ("-", depart, dest), $9.) ;                                                                                                                                                                                                           
    if dest &amp;lt; depart then city_pair = catx ("-", dest, depart) ;                                                                                                                                                                                                
    if h.find() ne 0 then ocu = _ocu ;                                                                                                                                                                                                                          
    else                  ocu + _ocu ;                                                                                                                                                                                                                          
    h.replace() ;                                                                                                                                                                                                                                               
  end ;                                                                                                                                                                                                                                                         
  h.output (dataset:"want") ;                                                                                                                                                                                                                                   
run ;            
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 01:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-based-on-2-Pairs-Airport-Data/m-p/620410#M182301</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2020-01-28T01:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Summing based on 2 Pairs (Airport Data)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-based-on-2-Pairs-Airport-Data/m-p/620413#M182303</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142314"&gt;@BCNAV&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You've had three good answer, yet none uses PROC SUMMARY, which I think of as the tool SAS intended to solve this problem. So, for completeness sake:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input depart $ dest $ ocu ;
  cards ;
cyyz  egll  500
cyvr  cyyz   10
egll  cyyz  500
;

data vneed/ view=vneed;
  set have;
  call sortc (depart,dest);
  length pair $9;
  pair=catx('-',depart,dest);
run;
proc summary data=vneed nway;
  class pair;
  var ocu;
  output out=want (drop=_type_ _freq_) sum=sumocu;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The nice thing about PROC SUMMARY is that it offers keywords that generate a lot of statistics in addition to SUM (e.g. mean, std, median, other percentiles, …).&amp;nbsp; And you could simultaneously do it not only for all pairs, but also for all DEPART values, and all DEST values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 02:26:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-based-on-2-Pairs-Airport-Data/m-p/620413#M182303</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-28T02:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Summing based on 2 Pairs (Airport Data)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-based-on-2-Pairs-Airport-Data/m-p/620423#M182305</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;: Mark, a nice complement. Truth be told, though, the crux of this problem isn't which particular tool to use for producing the sums but rather how to knead the input data to enable the &amp;nbsp;summation. I absolutely agree with what you've said of the broader functionality of SUMMARY, but all by itself it's powerless to face this problem head-on. Which, of course, can be said of any other aggregation method used in this thread.A truck may be able to carry a huge tree by its sheer weight; but it cannot do that before the tree is cut into shapes that can fill its bed properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 04:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-based-on-2-Pairs-Airport-Data/m-p/620423#M182305</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2020-01-28T04:03:19Z</dc:date>
    </item>
  </channel>
</rss>

