<?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 duplicate data when merging in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-data-when-merging/m-p/788361#M252041</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data set1;
input id $ weight age;
cards;
1 108 23
1 114 24
1 118 25
2 100 45
2 108 46
2 110 47
;
run;

data set2;
input id $ income :comma10. married $ smoking $;
cards;
1 40,000 y y
2 58,000 y n
;
run;

data want;
 merge set1 set2;
 by id;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Jan 2022 22:43:53 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2022-01-04T22:43:53Z</dc:date>
    <item>
      <title>How to duplicate data when merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-data-when-merging/m-p/788360#M252040</link>
      <description>&lt;P&gt;I am trying to merge two data sets. Dataset1 has multiple observations for each id, while dataset2 has a single row of observations for each id. I want to merge the data sets so that the observations in dataset2 are duplicated into each id in dataset1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example if this is the data set I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;dataset1;
input id $ weight age;
cards;
1 108 23
1 114 24
1 118 25
2 100 45
2 108 46
2 110 47
;
run;

dataset2;
input id $ income married $ smoking $
cards;
1 40,000 y y
2 58,000 y n
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to combine so that the final data set looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;datafinal;
input id $ weight age income married $ smoking $;
cards;
1 108 23 40,000 y y&amp;nbsp;
1 114 24 40,000 y y&amp;nbsp;
1 118 25 40,000 y y&amp;nbsp;
2 100 45 58,000 y n
2 108 46 58,000 y n
2 110 47 58,000 y n
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried doing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data combined;
     merge dataone datatwo;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but what I ended up was with&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;datafinal;
input id $ weight age income married $ smoking $;
1 108 23 40,000 y y&amp;nbsp;
1 114 24 
1 118 25 
2 100 45 58,000 y n
2 108 46 
2 110 47 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;because the data from dataset2 was not copied into each id in dataset1. Is there a way that I can duplicate data while merging two sets?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 22:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-data-when-merging/m-p/788360#M252040</guid>
      <dc:creator>pr1496</dc:creator>
      <dc:date>2022-01-04T22:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to duplicate data when merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-data-when-merging/m-p/788361#M252041</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data set1;
input id $ weight age;
cards;
1 108 23
1 114 24
1 118 25
2 100 45
2 108 46
2 110 47
;
run;

data set2;
input id $ income :comma10. married $ smoking $;
cards;
1 40,000 y y
2 58,000 y n
;
run;

data want;
 merge set1 set2;
 by id;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jan 2022 22:43:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-data-when-merging/m-p/788361#M252041</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2022-01-04T22:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to duplicate data when merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-data-when-merging/m-p/788363#M252043</link>
      <description>&lt;P&gt;use BY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data set1;
input id $ weight age;
cards;
1 108 23
1 114 24
1 118 25
2 100 45
2 108 46
2 110 47
;
run;

data set2;
input id $ income married $ smoking $;
cards;
1 40000 y y
2 58000 y n
;
run;

data combined;
     merge set1 set2;
     by id;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;B.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 22:46:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-data-when-merging/m-p/788363#M252043</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-01-04T22:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to duplicate data when merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-data-when-merging/m-p/788367#M252046</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try doing a LEFT JOIN instead of MERGE. Use the column ID for doing the JOIN function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 22:57:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-data-when-merging/m-p/788367#M252046</guid>
      <dc:creator>KaueMAlmeida</dc:creator>
      <dc:date>2022-01-04T22:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to duplicate data when merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-data-when-merging/m-p/788369#M252048</link>
      <description>&lt;P&gt;Many to one merges work fine with data step MERGE statement.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;But you have to tell it what variable(s) to use to match them.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;That is done with the BY statement.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;You should have seen a note in the log warning that you forgot to include the BY statement.&lt;/P&gt;
&lt;P&gt;Note that both datasets need to be sorted by the BY variable(s).&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 23:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-duplicate-data-when-merging/m-p/788369#M252048</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-04T23:29:51Z</dc:date>
    </item>
  </channel>
</rss>

