<?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: add one column from another table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/add-one-column-from-another-table/m-p/442779#M110725</link>
    <description>&lt;P&gt;- please provide example data in data steps, so we can recreate your data with copy/paste and submit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- what is the logical rule for combining A and B?&lt;/P&gt;</description>
    <pubDate>Tue, 06 Mar 2018 07:56:02 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-03-06T07:56:02Z</dc:date>
    <item>
      <title>add one column from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-one-column-from-another-table/m-p/442764#M110721</link>
      <description>&lt;P&gt;I have two table looks like and I want to add column score to tableA from tableB,then get tableC,how to do in SAS?&lt;/P&gt;&lt;P&gt;the only rule is to add a column in tableA name "score " and its value is same as column "score" in tableB(which are all the same in tableB)&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;+----+---+---+---+
| id | b | c | d |
+----+---+---+---+
|  1 | 5 | 7 | 2 |
|  2 | 6 | 8 | 3 |
|  3 | 7 | 8 | 1 |
|  4 | 5 | 7 | 2 |
|  5 | 6 | 8 | 3 |
|  6 | 7 | 8 | 1 |
+----+---+---+---+
       tableA

+---+---+-------+
| e | f | score |
+---+---+-------+
| 3 | 7 |    11 |
| 4 | 6 |    11 |
| 5 | 5 |    11 |
+---+---+-------+
      tableB

+----+---+---+---+-------+
| id | b | c | d | score |
+----+---+---+---+-------+
|  1 | 5 | 7 | 2 |    11 |
|  2 | 6 | 8 | 3 |    11 |
|  3 | 7 | 8 | 1 |    11 |
|  4 | 5 | 7 | 2 |    11 |
|  5 | 6 | 8 | 3 |    11 |
|  6 | 7 | 8 | 1 |    11 |
+----+---+---+---+-------+
       tableC&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 08:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-one-column-from-another-table/m-p/442764#M110721</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-03-06T08:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: add one column from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-one-column-from-another-table/m-p/442776#M110723</link>
      <description>&lt;P&gt;Please explain the rules to get the required observation from tableB.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 07:45:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-one-column-from-another-table/m-p/442776#M110723</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-03-06T07:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: add one column from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-one-column-from-another-table/m-p/442779#M110725</link>
      <description>&lt;P&gt;- please provide example data in data steps, so we can recreate your data with copy/paste and submit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- what is the logical rule for combining A and B?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 07:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-one-column-from-another-table/m-p/442779#M110725</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-06T07:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: add one column from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-one-column-from-another-table/m-p/442788#M110729</link>
      <description>&lt;P&gt;So there will always be only &lt;EM&gt;one&lt;/EM&gt; distinct value in tableB for score?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that case, create a macro variable from B and insert in A:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select score into :score from tableb (obs=1);
quit;

data tablea_new;
set tablea;
score = &amp;amp;score;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or do a simple merge with the first observation (to prevent unwanted observations if b contains more observations than a):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tablea_new;
merge
  tablea
  tableb (keep=score obs=1)
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Both codes untested, for lack of usable example data.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 08:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-one-column-from-another-table/m-p/442788#M110729</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-06T08:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: add one column from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-one-column-from-another-table/m-p/545249#M150810</link>
      <description>&lt;P&gt;&lt;SPAN&gt;KurtBremser&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This code works very well for numeric and i am very appreciative&amp;nbsp;of that, What would the code look like if the data were character?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 15:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-one-column-from-another-table/m-p/545249#M150810</guid>
      <dc:creator>Raymo70</dc:creator>
      <dc:date>2019-03-22T15:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: add one column from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-one-column-from-another-table/m-p/545699#M151021</link>
      <description>&lt;P&gt;Then you need to enclose the text created by the macro variable in quotes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;score = "&amp;amp;score.";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Mar 2019 06:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-one-column-from-another-table/m-p/545699#M151021</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-25T06:43:39Z</dc:date>
    </item>
  </channel>
</rss>

