<?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 Compare two tables column and get values of corresponding column value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-two-tables-column-and-get-values-of-corresponding/m-p/316756#M69270</link>
    <description>&lt;P&gt;First, sort both tables by siteid.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge
  tablea (in=a)
  tableb (in=b)
;
by siteid;
if a;
if b then users = users !! unique_user;
if last.siteid then output;
drop unique_user;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the append to users to be done with a delimiter, use the catx() function.&lt;/P&gt;
&lt;P&gt;Also make sure that users is long enough to hold all the values (add a length statement before the merge statement).&lt;/P&gt;</description>
    <pubDate>Mon, 05 Dec 2016 16:15:04 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-12-05T16:15:04Z</dc:date>
    <item>
      <title>How to Compare two tables column and get values of corresponding column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-two-tables-column-and-get-values-of-corresponding/m-p/316752#M69268</link>
      <description>&lt;P&gt;I have two table A and B. I want compare column B1 from Table B with A1 from Table A. Whichever values will be matched want to add B2 column from Table B corresponding values in A3 column of table A.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eg.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Table A,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Column :: &lt;/STRONG&gt;SiteID, Name, Users&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Table B&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Column ::&amp;nbsp;&lt;/STRONG&gt;SiteID, Uniue User&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Compare A.SiteID and B.SiteID. Whichever values will be matched want add B.Unique User corrensponding value to A.users&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 16:07:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-two-tables-column-and-get-values-of-corresponding/m-p/316752#M69268</guid>
      <dc:creator>aniketwagare0</dc:creator>
      <dc:date>2016-12-05T16:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to Compare two tables column and get values of corresponding column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-two-tables-column-and-get-values-of-corresponding/m-p/316755#M69269</link>
      <description>&lt;P&gt;Well, you've not posted any test data, so this code isn't tested:&lt;/P&gt;
&lt;PRE&gt;proc sort data=tablea;
  by siteid;
run;
proc sort data=tableb;
  by siteid;
run;
data want;
  merge tablea tableb;
  by siteid;
run;&lt;/PRE&gt;
&lt;P&gt;This will merge variables from second table to first based on matching siteid variable. &amp;nbsp;For future, its a good idea to post test data (in the form of a datastep), and what the output should look like.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 16:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-two-tables-column-and-get-values-of-corresponding/m-p/316755#M69269</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-05T16:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to Compare two tables column and get values of corresponding column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-two-tables-column-and-get-values-of-corresponding/m-p/316756#M69270</link>
      <description>&lt;P&gt;First, sort both tables by siteid.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge
  tablea (in=a)
  tableb (in=b)
;
by siteid;
if a;
if b then users = users !! unique_user;
if last.siteid then output;
drop unique_user;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the append to users to be done with a delimiter, use the catx() function.&lt;/P&gt;
&lt;P&gt;Also make sure that users is long enough to hold all the values (add a length statement before the merge statement).&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 16:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-two-tables-column-and-get-values-of-corresponding/m-p/316756#M69270</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-05T16:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to Compare two tables column and get values of corresponding column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-two-tables-column-and-get-values-of-corresponding/m-p/316758#M69271</link>
      <description>&lt;P&gt;Can tableB have siteIDs that are not in tableA ?&lt;/P&gt;
&lt;P&gt;If you want to add columns from tableB only if siteID matches you nead&lt;/P&gt;
&lt;P&gt;a slight change to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;&amp;nbsp;msrge step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  merge tablea &lt;STRONG&gt;(in=ina)&lt;/STRONG&gt;&lt;BR /&gt;        tableb;
  by siteid;&lt;BR /&gt;     &lt;STRONG&gt;if ina;&lt;/STRONG&gt;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Dec 2016 16:20:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-two-tables-column-and-get-values-of-corresponding/m-p/316758#M69271</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-05T16:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to Compare two tables column and get values of corresponding column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-two-tables-column-and-get-values-of-corresponding/m-p/316763#M69272</link>
      <description>&lt;P&gt;Can unique user be alraedy in tableA.users ?&lt;/P&gt;
&lt;P&gt;If yes - would you like to add it again ?&lt;/P&gt;
&lt;P&gt;Is tableA.users long enough to contain more users than original ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you meant to use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser﻿&lt;/a&gt;&amp;nbsp;code, you better make a slight change:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG&gt;length users $100;  /* assign max length forecast */&lt;/STRONG&gt;
&lt;SPAN class="token keyword"&gt;merge&lt;/SPAN&gt;
  tablea &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;a&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;
  tableb &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; siteid&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; b &lt;STRONG&gt;and index(users, unique_user) = 0&lt;/STRONG&gt; &lt;BR /&gt;&lt;SPAN class="token keyword"&gt;   then&lt;/SPAN&gt; users &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;STRONG&gt;compbl&lt;/STRONG&gt;(users &lt;SPAN class="token operator"&gt;!!&lt;/SPAN&gt; unique_user)&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; last&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;siteid &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; output&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;drop&lt;/SPAN&gt; unique_user&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Dec 2016 16:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Compare-two-tables-column-and-get-values-of-corresponding/m-p/316763#M69272</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-05T16:28:38Z</dc:date>
    </item>
  </channel>
</rss>

