<?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: Merge two tables and create new columns for values that match certain criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-and-create-new-columns-for-values-that-match/m-p/554599#M154296</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
 input Week     Brand    avgPrice ;
cards;
1             1                10
2             1                 11
1             2                 5
2             2                 6
1             3                 15
2             3                10
;

data table2;
input householdid      week         brand         dollars ;     
cards;
1                         1                  2              32
3                         2                  1              25
;
proc sort data=table1 out=temp(keep=week avgprice);
by week;
run;

proc transpose data=temp out=_temp(drop=_name_) prefix=Pricebrand;
by week;
var avgprice ;
run;
data want;
merge table2 _temp;
by week;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 28 Apr 2019 16:20:45 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-04-28T16:20:45Z</dc:date>
    <item>
      <title>Merge two tables and create new columns for values that match certain criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-and-create-new-columns-for-values-that-match/m-p/554598#M154295</link>
      <description>&lt;P&gt;Hi, I have 2 tables, the first one contains week, brand (4 choices) and avgPrice, the second one is the transaction panel data.&lt;/P&gt;&lt;P&gt;I want to display price of all brands in that week in the transaction data but do not know how.&lt;/P&gt;&lt;P&gt;my table is similar to the following:&lt;/P&gt;&lt;P&gt;table 1:&lt;/P&gt;&lt;P&gt;Week&amp;nbsp; &amp;nbsp; &amp;nbsp;Brand&amp;nbsp; &amp;nbsp; avgPrice&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/P&gt;&lt;P&gt;......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table2:&lt;/P&gt;&lt;P&gt;householdid&amp;nbsp; &amp;nbsp; &amp;nbsp; week&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;brand&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dollars&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 32&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 25&lt;/P&gt;&lt;P&gt;...............&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The table I want to create is like:&lt;/P&gt;&lt;P&gt;householdid&amp;nbsp; &amp;nbsp; &amp;nbsp; week&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;brand&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dollars&amp;nbsp; &amp;nbsp; &amp;nbsp; Pricebrand1&amp;nbsp; &amp;nbsp; Pricebrand2&amp;nbsp; &amp;nbsp; Pricebrand3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Pricebrand4&lt;/P&gt;&lt;P&gt;12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 32&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&lt;/P&gt;&lt;P&gt;43534&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 25&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;...............&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Apr 2019 16:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-and-create-new-columns-for-values-that-match/m-p/554598#M154295</guid>
      <dc:creator>Linh1</dc:creator>
      <dc:date>2019-04-28T16:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two tables and create new columns for values that match certain criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-and-create-new-columns-for-values-that-match/m-p/554599#M154296</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
 input Week     Brand    avgPrice ;
cards;
1             1                10
2             1                 11
1             2                 5
2             2                 6
1             3                 15
2             3                10
;

data table2;
input householdid      week         brand         dollars ;     
cards;
1                         1                  2              32
3                         2                  1              25
;
proc sort data=table1 out=temp(keep=week avgprice);
by week;
run;

proc transpose data=temp out=_temp(drop=_name_) prefix=Pricebrand;
by week;
var avgprice ;
run;
data want;
merge table2 _temp;
by week;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 Apr 2019 16:20:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-and-create-new-columns-for-values-that-match/m-p/554599#M154296</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-28T16:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two tables and create new columns for values that match certain criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-and-create-new-columns-for-values-that-match/m-p/554617#M154307</link>
      <description>Thank you so much!</description>
      <pubDate>Sun, 28 Apr 2019 19:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-and-create-new-columns-for-values-that-match/m-p/554617#M154307</guid>
      <dc:creator>Linh1</dc:creator>
      <dc:date>2019-04-28T19:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two tables and create new columns for values that match certain criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-and-create-new-columns-for-values-that-match/m-p/554618#M154308</link>
      <description>&lt;P&gt;Close, but if any brands are missing for any week you will have an alignment problem.&lt;/P&gt;
&lt;P&gt;Better to use ID statement in PROC TRANPOSE to determine the target variable name based on the brand id number.&lt;/P&gt;</description>
      <pubDate>Sun, 28 Apr 2019 19:37:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-and-create-new-columns-for-values-that-match/m-p/554618#M154308</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-28T19:37:55Z</dc:date>
    </item>
  </channel>
</rss>

