<?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: Distinc pairs of cities using proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115992#M259329</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What do you want? Pairs of cities, pairs of PIDs, pairs of city-PID combinations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me join the guessing game! Here are two more guesses as to what you may want:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;create table pairs1 as&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;select city, min(pid) as pid1, max(pid) as pid2 from places&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;group by city having range(pid) &amp;gt; 0;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;select * from pairs1;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;create table pairs2 as&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;select A.city as city1, B.city as city2&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;from places as A inner join places as B &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;on A.city &amp;lt; B.city;&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;select * from pairs2; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;Excuse me if I don't spend too much time on those answers, you obviously didn't spend much on the question...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;PG&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 Apr 2013 19:04:07 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2013-04-22T19:04:07Z</dc:date>
    <item>
      <title>Distinc pairs of cities using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115989#M259326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier;"&gt;any idea,anyone pleasE?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier;"&gt;data places;&lt;BR /&gt; input pid city $12.;&lt;BR /&gt; cards; &lt;BR /&gt; 1 LosAngeles&lt;BR /&gt; 2 Orlando&lt;BR /&gt; 3 London&lt;BR /&gt; 4 NewYork&lt;BR /&gt; 5 Boston&lt;BR /&gt; 6 Paris&lt;BR /&gt; 7 Washington&lt;BR /&gt; 8 LosAngeles&lt;BR /&gt; 9 Orlando&lt;BR /&gt; 10 London&lt;BR /&gt; ;&lt;BR /&gt; run;&lt;/SPAN&gt;&lt;SPAN style="font-family: Times New Roman;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 18:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115989#M259326</guid>
      <dc:creator>Tal</dc:creator>
      <dc:date>2013-04-22T18:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Distinc pairs of cities using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115990#M259327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tal,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your requirements are very sketchy here, so I am making some assumptions.&amp;nbsp; What about:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table paired_cities as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select distinct city&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,min(pid) as small_pid&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,max(pid) as large_pid&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from places&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; group by city&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; having count(*) = 2&lt;BR /&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 18:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115990#M259327</guid>
      <dc:creator>LarryWorley</dc:creator>
      <dc:date>2013-04-22T18:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Distinc pairs of cities using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115991#M259328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you can easily generate pairs this way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table pairs as&lt;/P&gt;&lt;P&gt;select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.pid as Pid_1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.city as City_1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t2.pid as PId_2,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t2.city as City_2&lt;/P&gt;&lt;P&gt;from&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; places p1, places p2&lt;/P&gt;&lt;P&gt;where&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p1.pid ne p2.pid;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One issue might be that this approach includes both LosAngeles, Orlando and Orlando, LosAngeles.&amp;nbsp; You can avoid this by:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table unique_paris as&lt;/P&gt;&lt;P&gt;select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.pid as PId_1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.city as City_1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t2.pid as PId_2,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t2.city as City_2&lt;/P&gt;&lt;P&gt;from&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; places t1, places t2&lt;/P&gt;&lt;P&gt;where&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t2.pid &amp;gt; t1.pid;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 18:55:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115991#M259328</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2013-04-22T18:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Distinc pairs of cities using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115992#M259329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What do you want? Pairs of cities, pairs of PIDs, pairs of city-PID combinations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me join the guessing game! Here are two more guesses as to what you may want:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;create table pairs1 as&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;select city, min(pid) as pid1, max(pid) as pid2 from places&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;group by city having range(pid) &amp;gt; 0;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;select * from pairs1;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;create table pairs2 as&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;select A.city as city1, B.city as city2&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;from places as A inner join places as B &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;on A.city &amp;lt; B.city;&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;select * from pairs2; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;Excuse me if I don't spend too much time on those answers, you obviously didn't spend much on the question...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;PG&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 19:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115992#M259329</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-04-22T19:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Distinc pairs of cities using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115993#M259330</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sorry guys i was not more specific&lt;/P&gt;&lt;P&gt;this is what i am supposed to get:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier;"&gt;1 Boston London&lt;BR /&gt; 2 Boston LosAngeles&lt;BR /&gt; 3 Boston NewYork&lt;BR /&gt; 4 Boston Orlando&lt;BR /&gt; 5 Boston Paris&lt;BR /&gt; 6 Boston Washington&lt;BR /&gt; 7 London LosAngeles&lt;BR /&gt; 8 London NewYork&lt;BR /&gt; 9 London Orlando&lt;BR /&gt; 10 London Paris&lt;BR /&gt; 11 London Washington&lt;BR /&gt; 12 LosAngeles NewYork&lt;BR /&gt; 13 LosAngeles Orlando&lt;BR /&gt; 14 LosAngeles Paris&lt;BR /&gt; 15 LosAngeles Washington&lt;BR /&gt; 16 NewYork Orlando&lt;BR /&gt; 17 NewYork Paris&lt;BR /&gt; 18 NewYork Washington&lt;BR /&gt; 19 Orlando Paris&lt;BR /&gt; 20 Orlando Washington&lt;BR /&gt; 21 Paris Washington&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 19:45:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115993#M259330</guid>
      <dc:creator>Tal</dc:creator>
      <dc:date>2013-04-22T19:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: Distinc pairs of cities using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115994#M259331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Then adding &lt;STRONG&gt;distinct&lt;/STRONG&gt;&amp;nbsp; and &lt;STRONG&gt;order by &lt;/STRONG&gt;clause to PGStats second guess will get you this result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;create table pairs2 as&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;select &lt;/STRONG&gt;distinct &lt;STRONG&gt;A.city as city1, B.city as city2&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;from places as A inner join places as B &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;on A.city &amp;lt; B.city&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;order by a.city, b.city &lt;STRONG&gt;;&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;select * from pairs2; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 19:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115994#M259331</guid>
      <dc:creator>LarryWorley</dc:creator>
      <dc:date>2013-04-22T19:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Distinc pairs of cities using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115995#M259332</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sweet.&lt;/P&gt;&lt;P&gt;Thanks Larry,&lt;/P&gt;&lt;P&gt;thanks guys for your time and efforts&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 20:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinc-pairs-of-cities-using-proc-sql/m-p/115995#M259332</guid>
      <dc:creator>Tal</dc:creator>
      <dc:date>2013-04-22T20:01:38Z</dc:date>
    </item>
  </channel>
</rss>

