<?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: How to make a Cartesian product, by group, of character observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731710#M227943</link>
    <description>&lt;P&gt;But they are character variables. How can I determine one side is quantitatively greater than the other side?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Apr 2021 20:31:28 GMT</pubDate>
    <dc:creator>KS99</dc:creator>
    <dc:date>2021-04-06T20:31:28Z</dc:date>
    <item>
      <title>How to make a Cartesian product, by group, of character observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731684#M227929</link>
      <description>&lt;P&gt;Hi, greetings,&lt;/P&gt;&lt;P&gt;If anyone can help me with this, I will greatly appreciate it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose I have the following dataset,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data HAVE;&amp;nbsp;&lt;BR /&gt;input&amp;nbsp; ID&amp;nbsp; year $ country;&lt;BR /&gt;cards;&lt;BR /&gt;1&amp;nbsp; 2000 USA&lt;BR /&gt;1&amp;nbsp; 2000 ESP&lt;BR /&gt;2&amp;nbsp; 2004 GBR&lt;BR /&gt;2&amp;nbsp; 2004 USA&lt;BR /&gt;2&amp;nbsp; 2004 NLD&lt;BR /&gt;2&amp;nbsp; 2005 USA&lt;BR /&gt;2&amp;nbsp; 2005 DEU&lt;BR /&gt;2&amp;nbsp; 2005 ISR&lt;BR /&gt;2&amp;nbsp; 2005 CHE&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new dataset that looks like below,&amp;nbsp;&lt;/P&gt;&lt;P&gt;__________________________&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; year country1 country2;&lt;BR /&gt;1&amp;nbsp; 2000 USA ESP&amp;nbsp;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2004 GBR USA&amp;nbsp;&lt;BR /&gt;2&amp;nbsp; 2004 USA NLD&amp;nbsp;&lt;BR /&gt;2&amp;nbsp; 2004 NLD GBR&amp;nbsp;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2005 USA DEU&lt;BR /&gt;2&amp;nbsp; 2005 USA ISR&amp;nbsp;&lt;BR /&gt;2&amp;nbsp; 2005 USA CHE&amp;nbsp;&lt;BR /&gt;2&amp;nbsp; 2005 DEU ISR&lt;/P&gt;&lt;P&gt;2 2005 DEU CHE&lt;BR /&gt;2 2005 ISR CHE&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;...&lt;BR /&gt;________________________&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In other words, I want to form a every possible (Cartesian) pair-product of countries, by ID and year, without duplicates (for example, DEU-CHE and&amp;nbsp; CHE-DEU are the same, therefore only one of the two are entered).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many times I obtain a great help from SAS communities, and&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you can help me one more time this time, I will be more than thankful to you guys.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a wonderful day!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 19:26:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731684#M227929</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-04-06T19:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a Cartesian product, by group, of character observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731686#M227931</link>
      <description>CROSS JOIN with year and ensure that one side is greater than the other side to avoid duplicates.</description>
      <pubDate>Tue, 06 Apr 2021 19:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731686#M227931</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-06T19:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a Cartesian product, by group, of character observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731710#M227943</link>
      <description>&lt;P&gt;But they are character variables. How can I determine one side is quantitatively greater than the other side?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 20:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731710#M227943</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-04-06T20:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a Cartesian product, by group, of character observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731716#M227946</link>
      <description>&lt;P&gt;Try the suggestion. Alphabetical order for characters will work as expected.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 20:42:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731716#M227946</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-06T20:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a Cartesian product, by group, of character observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731717#M227947</link>
      <description>&lt;P&gt;Oh really? Thank you !!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 20:45:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731717#M227947</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-04-06T20:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a Cartesian product, by group, of character observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731719#M227949</link>
      <description>&lt;P&gt;I am such a Newbie in SAS..&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you provide a clue code to achieve this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 20:59:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731719#M227949</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-04-06T20:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a Cartesian product, by group, of character observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731750#M227969</link>
      <description>&lt;P&gt;From your requirement you want combination of countries by year and ID and no duplicates.&lt;BR /&gt;From the required output given in your question you want all combination of countries.&lt;BR /&gt;While there are many approaches to the solution, with the understanding I have of your requirements, I suggest the following code.&lt;BR /&gt;This is an example try modifications / improvements as needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE; 
input  ID  year  country $;
cards;
1  2000 USA
1  2000 ESP
2  2004 GBR
2  2004 USA
2  2004 NLD
2  2005 USA
2  2005 DEU
2  2005 ISR
2  2005 CHE

;
run; 
proc sql;
create table want as
select a.* , b.country as country2 from have  a cross join have  b
where a.country ne b.country
order by id, year, country;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Apr 2021 23:32:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731750#M227969</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-04-06T23:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a Cartesian product, by group, of character observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731771#M227977</link>
      <description>&lt;LI-CODE lang="sas"&gt;where a.country gt b.country&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 07 Apr 2021 00:55:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/731771#M227977</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-04-07T00:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a Cartesian product, by group, of character observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/732120#M228128</link>
      <description>&lt;P&gt;Thank you ChrisNZ !&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code was producing Cartesian productions of all countries against all countries;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it gave me a clue how to do it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I separated two datasets, and using a chain of&amp;nbsp;where (a.ID=b.ID and a.year=b.year and a.country gt b.country1),&amp;nbsp;&lt;/P&gt;&lt;P&gt;obtained my wished-for results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 00:38:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-Cartesian-product-by-group-of-character/m-p/732120#M228128</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2021-04-08T00:38:43Z</dc:date>
    </item>
  </channel>
</rss>

