<?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: Array to Join text in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720092#M223035</link>
    <description>&lt;P&gt;this line&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;if ^index(NOTE,cats(I)) then do;&lt;/LI-CODE&gt;
&lt;P&gt;is the same as&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;if not index(NOTE,cats(I)) then do;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Feb 2021 03:00:41 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-02-18T03:00:41Z</dc:date>
    <item>
      <title>Array to Join text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720058#M223020</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;My data has a list of Name column (name1-name3) corresponding to var column (var1-var3).&lt;BR /&gt;I want to compare name(i) with name(j). If they are the same, I will join var(i) and var(j) under a new variable name var_ij.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on my data want, the output should be like that&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for row 1, as name1=name2, &lt;STRONG&gt;note&lt;/STRONG&gt; will be 12 and &lt;STRONG&gt;jointext_12&lt;/STRONG&gt;=1,2&lt;BR /&gt;for row 2, as name1=name3, &lt;STRONG&gt;note&lt;/STRONG&gt; will be 13 and &lt;STRONG&gt;jointext_13&lt;/STRONG&gt;=10,30&lt;BR /&gt;for row 3, as name1=name2=name3, &lt;STRONG&gt;note&lt;/STRONG&gt; will be 123 and &lt;STRONG&gt;jointext_123&lt;/STRONG&gt;=100,200,300&lt;/P&gt;
&lt;P&gt;for row4, as name2=name3, note will be 23 and jointext_23 =2000,3000&lt;/P&gt;
&lt;P&gt;Row 5 has no name the same, so there is nothing to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please help with my problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; input name1 $ name2 $ name3 $ var1 var2 var3;
datalines;
aa aa abc 1 2 3
aa dsd aa 10 20 30
aa aa aa 100 200 300
cc aa aa 1000 2000 3000
aa bb cc 1 2 3
;run;

data want; set have;
array name(*) name1-name3;
	do i=1 to dim(name)-1;
	do j=i+1 to dim(name);
		if name[i]=name[j] then do; 
			note=cat(i,j); 
			jointext_&amp;amp;i&amp;amp;j=catx(','var&amp;amp;i,var&amp;amp;j);
			end; 
	end;
	end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 23:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720058#M223020</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2021-02-17T23:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Array to Join text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720072#M223024</link>
      <description>&lt;P&gt;Please try to describe the rules a little clearer. Listing examples does not provide a rule.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And where do the two macro variables get the values from?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you expecting to use this as a "generic" solution for an unknown number of Name and var variables?&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 23:21:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720072#M223024</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-17T23:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: Array to Join text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720073#M223025</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT; 
  set HAVE;
  array NAME[*] NAME1-NAME3 ;
  array VAR[*] VAR1-VAR3;
  length NOTE JOIN $40;
	do I=1 to dim(NAME)-1;
  	do J=I+1 to dim(NAME);
      if NAME[I]=NAME[J] then do;     
        if ^index(NOTE,cats(I)) then do;
          NOTE=catx(',',NOTE,I); 
          JOIN=catx(',',JOIN,VAR[I]);
         end; 
  	     if ^index(NOTE,cats(J)) then do;
           NOTE=catx(',',NOTE,J); 
  	       JOIN=catx(',',JOIN,VAR[J]);
         end; 
      end; 
    end;                 
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I do not believe creating variable names with data in the name is a good idea, so I skipped that.&lt;/P&gt;
&lt;DIV class="branch"&gt;&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;NOTE&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;JOIN&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;1,2&lt;/TD&gt;
&lt;TD class="l data"&gt;1,2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;1,3&lt;/TD&gt;
&lt;TD class="l data"&gt;10,30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;1,2,3&lt;/TD&gt;
&lt;TD class="l data"&gt;100,200,300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;2,3&lt;/TD&gt;
&lt;TD class="l data"&gt;2000,3000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 23:30:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720073#M223025</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-02-17T23:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: Array to Join text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720075#M223026</link>
      <description>&lt;P&gt;Is this supposed to generalize to more than 3 names?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, you will need a rule for multiple values having matches&amp;nbsp; (i.e. 'aa','bb','aa','bb','aa'). And you won't be able to just instantly look for matches as you currently attepmt.&amp;nbsp; You'll have to determine whichever value has the most matches, assuming that is the goal.&amp;nbsp; Not to mention you'll need a rule for what to do if you have ties.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if it's only 3 names then arrays are no particular help. You would just to direct comparisons using the variable names.&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;But if you do need an array, then you need an array over names, as you have specified, and also an array over vars, which you haven't (instead you are attempting to use macro value which won't help here).&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 23:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720075#M223026</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-02-17T23:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: Array to Join text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720077#M223027</link>
      <description>&lt;P&gt;Can you have two multiples? Ie aa, aa, ab, ab =&amp;gt; 2xaa and 2xab?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would flip it long, sort and combine into the desired calculation. And then transpose&amp;nbsp; it back. I suspect you want to check a few different combinations&amp;nbsp; and a long form would work better as it's easier to control the join conditions. Depending on exactly what you're doing you may also want to consider dummy coding the values instead and then using PROC CORR to get a distance type matrix trick but you didn't explain what you're trying to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 00:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720077#M223027</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-18T00:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Array to Join text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720084#M223031</link>
      <description>&lt;P&gt;WOW, that's amazing piece of code.&lt;/P&gt;
&lt;P&gt;I wonder what this line do?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if ^index(NOTE,cats(I)) then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you so much.&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 01:50:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720084#M223031</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2021-02-18T01:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: Array to Join text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720092#M223035</link>
      <description>&lt;P&gt;this line&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;if ^index(NOTE,cats(I)) then do;&lt;/LI-CODE&gt;
&lt;P&gt;is the same as&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;if not index(NOTE,cats(I)) then do;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 03:00:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-to-Join-text/m-p/720092#M223035</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-02-18T03:00:41Z</dc:date>
    </item>
  </channel>
</rss>

