<?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: Create combination of value and name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-combination-of-value-and-name/m-p/839107#M331772</link>
    <description>&lt;P&gt;This is an instructional case to show the benefits of defining two hash iterators for a single hash object.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's a hash analog of "do i=1 to n;&amp;nbsp; do j=1 to n:" where there are subsequent references to x{i} and x{j}:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input name $ value;
datalines;
v1 3
v1 9
v1 2
v2 0
v2 1
v3 30
v3 35
run;

data want (drop=_:);
  if 0 then set have (rename=(name=name1 value=value1)) 
                have (rename=(name=name2 value=value2)) ;

  declare hash h (dataset:'have (rename=(name=name2 value=value2))',ordered:'a');
    h.definekey(all:'Y');
    h.definedata(all:'Y');
    h.definedone();
  declare hiter hi ('h');
  declare hiter hj ('h');

  do _rci=hi.first() by 0 until (hi.next()^=0);
    name1=name2;
    value1=value2;
    do _rcj=hj.first() by 0 until (hj.next()^=0);
      if name1^=name2 then output;
    end;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Oct 2022 01:04:34 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-10-18T01:04:34Z</dc:date>
    <item>
      <title>Create combination of value and name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-combination-of-value-and-name/m-p/839090#M331761</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I have a data of 2 columns: Name and value.&lt;/P&gt;
&lt;P&gt;Name and value are unique pair.&lt;/P&gt;
&lt;P&gt;I want to create combination of 2 name and value.&lt;/P&gt;
&lt;P&gt;For example, the output should be like&lt;/P&gt;
&lt;P&gt;a_name | a_value | b_name | b_value&lt;/P&gt;
&lt;P&gt;v1 3 v2 0&lt;/P&gt;
&lt;P&gt;v1 3 v2 1&lt;/P&gt;
&lt;P&gt;v1 3 v3 30&lt;/P&gt;
&lt;P&gt;v1 3 v3 35&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;v1 9 v2 0&lt;/P&gt;
&lt;P&gt;v1 9 v2 1&lt;/P&gt;
&lt;P&gt;.....&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input name $ value;
datalines;
v1 3
v1 9
v1 2
v2 0
v2 1
v3 30
v3 35
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 21:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-combination-of-value-and-name/m-p/839090#M331761</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-10-17T21:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create combination of value and name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-combination-of-value-and-name/m-p/839096#M331764</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input name $ value;
datalines;
v1 3
v1 9
v1 2
v2 0
v2 1
v3 30
v3 35
;run;

proc sql;
create table want as 
select a.*, b.name as name2, b.value as value2
from have a cross join have b
where a.name&amp;lt;&amp;gt;b.name and a.value&amp;lt;&amp;gt;b.value;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Oct 2022 22:13:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-combination-of-value-and-name/m-p/839096#M331764</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-10-17T22:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create combination of value and name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-combination-of-value-and-name/m-p/839097#M331765</link>
      <description>Looks like a cross join, you don't show any V1, V1 pairs, is that intentional?&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Oct 2022 22:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-combination-of-value-and-name/m-p/839097#M331765</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-17T22:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create combination of value and name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-combination-of-value-and-name/m-p/839100#M331767</link>
      <description>&lt;P&gt;This sql join method will create "duplicate" combination.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select a.*, b.name as name2, b.value as value2
from have a cross join have b
where a.name&amp;lt;&amp;gt;b.name;
quit;

data dup; set want;
if name ='v1' and value=3 and name2='v2' and value2=0 then output;
if name ='v2' and value=0 and name2='v1' and value2=3 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Oct 2022 22:41:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-combination-of-value-and-name/m-p/839100#M331767</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-10-17T22:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create combination of value and name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-combination-of-value-and-name/m-p/839101#M331768</link>
      <description>&lt;P&gt;V1 V1 combi is not needed, Reeza.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 22:41:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-combination-of-value-and-name/m-p/839101#M331768</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-10-17T22:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: Create combination of value and name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-combination-of-value-and-name/m-p/839107#M331772</link>
      <description>&lt;P&gt;This is an instructional case to show the benefits of defining two hash iterators for a single hash object.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's a hash analog of "do i=1 to n;&amp;nbsp; do j=1 to n:" where there are subsequent references to x{i} and x{j}:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input name $ value;
datalines;
v1 3
v1 9
v1 2
v2 0
v2 1
v3 30
v3 35
run;

data want (drop=_:);
  if 0 then set have (rename=(name=name1 value=value1)) 
                have (rename=(name=name2 value=value2)) ;

  declare hash h (dataset:'have (rename=(name=name2 value=value2))',ordered:'a');
    h.definekey(all:'Y');
    h.definedata(all:'Y');
    h.definedone();
  declare hiter hi ('h');
  declare hiter hj ('h');

  do _rci=hi.first() by 0 until (hi.next()^=0);
    name1=name2;
    value1=value2;
    do _rcj=hj.first() by 0 until (hj.next()^=0);
      if name1^=name2 then output;
    end;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 01:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-combination-of-value-and-name/m-p/839107#M331772</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-10-18T01:04:34Z</dc:date>
    </item>
  </channel>
</rss>

