<?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 find the union and intersection of two string combos in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492634#M6142</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;

var1="word1 word2 word3 word4";
var2="word4 word3                  ";
output;

var2="word1 word2 word3 word4";
var1="word5 word6";
output;

var1="word1 word2 word3 word4";
var2="word1 word3";
output;

run;

data want;
 set have;
 length intersect union $ 200;
 array x{99} $ 32;
 n=0; 
 do i=1 to countw(var1,' ');
  temp=scan(var1,i,' ');
  if temp not in x then do;n+1;x{n}=temp;end;
 end;
 do i=1 to countw(var2,' ');
  temp=scan(var2,i,' ');
  if temp not in x then do;n+1;x{n}=temp;end;
   else intersect=catx(' ',intersect,temp);
 end;
 union=catx(' ',of x{*});
drop x: n i temp;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 05 Sep 2018 12:57:32 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-09-05T12:57:32Z</dc:date>
    <item>
      <title>How to find the union and intersection of two string combos</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492517#M6134</link>
      <description>&lt;P&gt;Hello, community.&lt;/P&gt;&lt;P&gt;I am fairly new to SAS programming and get stuck on this:&lt;/P&gt;&lt;P&gt;Suppose I have two string combos as: combo1(word1 word2 word3 ) combo2(word2, word3, word4), how can I output:&lt;/P&gt;&lt;P&gt;the union of these two combos as: (word1, word2, word3, word4)&lt;/P&gt;&lt;P&gt;the intersection of these two combos as: (word2, word3)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any comment is highly appreciated!!!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 01:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492517#M6134</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-09-05T01:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the union and intersection of two string combos</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492520#M6135</link>
      <description>&lt;P&gt;Best best is to separate the strings into the individual components and then use proc sort to remove duplicates.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on if you know the length of the string and it's fixed or dynamic there may be other approaches.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/230703"&gt;@lpy0521&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello, community.&lt;/P&gt;
&lt;P&gt;I am fairly new to SAS programming and get stuck on this:&lt;/P&gt;
&lt;P&gt;Suppose I have two string combos as: combo1(word1 word2 word3 ) combo2(word2, word3, word4), how can I output:&lt;/P&gt;
&lt;P&gt;the union of these two combos as: (word1, word2, word3, word4)&lt;/P&gt;
&lt;P&gt;the intersection of these two combos as: (word2, word3)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any comment is highly appreciated!!!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 01:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492520#M6135</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-05T01:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the union and intersection of two string combos</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492523#M6136</link>
      <description>&lt;P&gt;General approach:&amp;nbsp; create additional variables COMBO3 and COMBO4 holding the results you want.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS has tools (FINDW, SCAN) that make this task possible.&amp;nbsp; But to start programming, you have to clarify:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Do the incoming variables actually contain parentheses?&lt;/LI&gt;
&lt;LI&gt;Do the incoming variables actually contain commas?&lt;/LI&gt;
&lt;LI&gt;Same questions for the results ... are parentheses and commas required?&amp;nbsp; Optional?&lt;/LI&gt;
&lt;LI&gt;Are two words considered to be the same if they contain the same letters but different capitalization?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 02:20:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492523#M6136</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-05T02:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the union and intersection of two string combos</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492527#M6137</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Best best is to separate the strings into the individual components and then use proc sort to remove duplicates.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Depending on if you know the length of the string and it's fixed or dynamic there may be other approaches.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/230703"&gt;@lpy0521&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Hello, community.&lt;/P&gt;&lt;P&gt;I am fairly new to SAS programming and get stuck on this:&lt;/P&gt;&lt;P&gt;Suppose I have two string combos as: combo1(word1 word2 word3 ) combo2(word2, word3, word4), how can I output:&lt;/P&gt;&lt;P&gt;the union of these two combos as: (word1, word2, word3, word4)&lt;/P&gt;&lt;P&gt;the intersection of these two combos as: (word2, word3)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any comment is highly appreciated!!!&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;My string combo actually contains more than 10 words, so split into individual component may create too many redundant variables for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 02:47:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492527#M6137</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-09-05T02:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the union and intersection of two string combos</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492530#M6138</link>
      <description>&lt;P&gt;Why create multiple variables? You can have a single variable with multiple values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/230703"&gt;@lpy0521&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;My string combo actually contains more than 10 words, so split into individual component may create too many redundant variables for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 02:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492530#M6138</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-05T02:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the union and intersection of two string combos</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492531#M6139</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;General approach:&amp;nbsp; create additional variables COMBO3 and COMBO4 holding the results you want.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS has tools (FINDW, SCAN) that make this task possible.&amp;nbsp; But to start programming, you have to clarify:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Do the incoming variables actually contain parentheses?&lt;/LI&gt;&lt;LI&gt;Do the incoming variables actually contain commas?&lt;/LI&gt;&lt;LI&gt;Same questions for the results ... are parentheses and commas required?&amp;nbsp; Optional?&lt;/LI&gt;&lt;LI&gt;Are two words considered to be the same if they contain the same letters but different capitalization?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;For the incoming variables, each words are space delimited and all in Capital, no parentheses nor commas required. For the results, the same criteria applies: space delimited and in cap and no parentheses or commas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If would be very grateful if you can show me some sample code on how to achieve this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 02:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492531#M6139</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-09-05T02:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the union and intersection of two string combos</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492535#M6140</link>
      <description>&lt;P&gt;Can you post some sample data to accurately reflect your data? Quick example is below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;

var1="word1, word2, word3, word4";
var2="word4, word3";
output;

var1="word1, word2, word3, word4";
var2="word4, word3";
output;

var1="word1, word2, word3, word4";
var2="word4, word3";
output;

run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Sep 2018 03:13:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492535#M6140</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-05T03:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the union and intersection of two string combos</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492540#M6141</link>
      <description>&lt;P&gt;Building on &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;example set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;

var1="word1 word2 word3 word4";
var2="word4 word3";
output;

var1="word1 word2 word3 word4";
var2="word5 word6";
output;

var1="word1 word2 word3 word4";
var2="word1 word3";
output;

run;

data want;
length word $16 var3 var4 $120;
set have;
var3 = var1;
var4 = " ";
do i = 1 to countw(var2);
    word = scan(var2, i);
    if not findw(var3, word,, "ts") then var3 = catx(" ", var3, word);
    if findw(var1, word,, "ts") then var4 = catx(" ", var4, word);
    end;
drop word i;
run;

proc print data=want noobs; run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Sep 2018 04:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492540#M6141</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-09-05T04:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the union and intersection of two string combos</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492634#M6142</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;

var1="word1 word2 word3 word4";
var2="word4 word3                  ";
output;

var2="word1 word2 word3 word4";
var1="word5 word6";
output;

var1="word1 word2 word3 word4";
var2="word1 word3";
output;

run;

data want;
 set have;
 length intersect union $ 200;
 array x{99} $ 32;
 n=0; 
 do i=1 to countw(var1,' ');
  temp=scan(var1,i,' ');
  if temp not in x then do;n+1;x{n}=temp;end;
 end;
 do i=1 to countw(var2,' ');
  temp=scan(var2,i,' ');
  if temp not in x then do;n+1;x{n}=temp;end;
   else intersect=catx(' ',intersect,temp);
 end;
 union=catx(' ',of x{*});
drop x: n i temp;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Sep 2018 12:57:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/492634#M6142</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-09-05T12:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the union and intersection of two string combos</title>
      <link>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/493118#M6153</link>
      <description>&lt;P&gt;For a discussion of how to use COUNTW and SCAN to split a string into words (with arbitrary delimiters), see the article &lt;A href="https://blogs.sas.com/content/iml/2016/07/11/break-sentence-into-words-sas.html" target="_self"&gt;"Break a sentence into words in SAS."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;You can then use KSharp's&amp;nbsp;approach to find the union and intersection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For&amp;nbsp;SAS/IML programmers, the solution is quite short:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
a = "to be or not to be";
b = "2 b or not 2 b";
delims = ' ,.!';
a = scan(a, 1:countw(a, delims), delims); 
b = scan(b, 1:countw(b, delims), delims); 
intersect = xsect(a,b);
union = union(a,b);
print intersect, union;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Sep 2018 17:24:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/How-to-find-the-union-and-intersection-of-two-string-combos/m-p/493118#M6153</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-09-06T17:24:09Z</dc:date>
    </item>
  </channel>
</rss>

