<?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: Find matching columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-matching-columns/m-p/801150#M315279</link>
    <description>&lt;P&gt;I don't understand the logic here. Please explain further. I also don't see where any "matching columns" comes into play.&lt;/P&gt;</description>
    <pubDate>Wed, 09 Mar 2022 17:26:01 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-03-09T17:26:01Z</dc:date>
    <item>
      <title>Find matching columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-matching-columns/m-p/801146#M315275</link>
      <description>&lt;P&gt;I have a large dataset that looks like this:&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=""&gt;data have;
input finalVal value1 value2 value3;
datalines;
5 1 2 5
6 26 6 10
29 4 9 1
7 35 1 7
;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to find which of the 3 columns match and output that to a new column&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want;
input finalVal value1 value2 value3 matching_column $;
datalines;
5 1 2 5 value3
6 26 6 10 value2
29 4 9 1 none
7 35 1 7 value3
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;is this doable within a single proc sql or data step?&lt;/P&gt;&lt;P&gt;I was thinking I could make a series of if statements for everything, but I'm not sure if there is a more efficient way of doing this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate any input, thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 17:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-matching-columns/m-p/801146#M315275</guid>
      <dc:creator>raddad34</dc:creator>
      <dc:date>2022-03-09T17:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: Find matching columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-matching-columns/m-p/801150#M315279</link>
      <description>&lt;P&gt;I don't understand the logic here. Please explain further. I also don't see where any "matching columns" comes into play.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 17:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-matching-columns/m-p/801150#M315279</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-09T17:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: Find matching columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-matching-columns/m-p/801151#M315280</link>
      <description>&lt;P&gt;Do you want the variable name or just the index?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

array _search(3) value1-value3;

index = whichn(finalVal, of _search(*));
if index ne 0 then variableName = vname(_search(index));
else variableName = 'none';

run;&lt;/CODE&gt;&lt;/PRE&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/391589"&gt;@raddad34&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a large dataset that looks like this:&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=""&gt;data have;
input finalVal value1 value2 value3;
datalines;
5 1 2 5
6 26 6 10
29 4 9 1
7 35 1 7
;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to find which of the 3 columns match and output that to a new column&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data want;
input finalVal value1 value2 value3 matching_column $;
datalines;
5 1 2 5 value3
6 26 6 10 value2
29 4 9 1 none
7 35 1 7 value3
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is this doable within a single proc sql or data step?&lt;/P&gt;
&lt;P&gt;I was thinking I could make a series of if statements for everything, but I'm not sure if there is a more efficient way of doing this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would appreciate any input, thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 17:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-matching-columns/m-p/801151#M315280</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-03-09T17:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: Find matching columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-matching-columns/m-p/801153#M315281</link>
      <description>It is doable. There is a varname function that returns variable name. Please look at the example here:&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/sclref/9.4/p16g1sss185es1n1k1dhbxhsdqi2.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/sclref/9.4/p16g1sss185es1n1k1dhbxhsdqi2.htm&lt;/A&gt;</description>
      <pubDate>Wed, 09 Mar 2022 17:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-matching-columns/m-p/801153#M315281</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-03-09T17:47:46Z</dc:date>
    </item>
  </channel>
</rss>

