<?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 merge a smaller dataset into a larger dataset with repetition? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926533#M364608</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465588"&gt;@mmaxiu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, Tom.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your reply and the suggestions! Here's an example to clarify. Based on the tables above, I want to take the value of smallclient in row 1 of the smaller table and show its value for all combinations of au = 0 and fyear = 2011 in the larger table. So, the output I'm looking for in a merged table is for rows 1 through 15 from the larger table to have the variable smallclient show as zero for every single row. This would then be repeated for the whole larger table of 6841 rows.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is exactly what a simple MERGE will do.&amp;nbsp; As long as SMALLCLIENT does NOT already exist as a variable in the second table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
  input id lookup $;
cards;
1 A
2 B
3 C
;

data many ;
  input id other $;
cards;
1 X
1 Y
1 Z
2 W
4 V
;

data want;
  merge many one ;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    id    other    lookup

 1      1      X        A
 2      1      Y        A
 3      1      Z        A
 4      2      W        B
 5      3               C
 6      4      V
&lt;/PRE&gt;</description>
    <pubDate>Tue, 30 Apr 2024 20:31:02 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-04-30T20:31:02Z</dc:date>
    <item>
      <title>How to merge a smaller dataset into a larger dataset with repetition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926521#M364603</link>
      <description>&lt;P&gt;Hi, everyone.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to merge a smaller dataset into a larger dataset with repetition of the values of a specific variable from the small dataset. I want to take the smallclient variable from the first table below and add that variable with repetition to the second table below for each combination of au and fyear. I tried to code this with the following, but it failed. How would I code this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;*merge with repeated values - first example failed testgroup2 is the larger dataset;&lt;BR /&gt;&lt;BR /&gt;data Practice.merged_testgroup;&lt;BR /&gt;  merge Practice.testgroup2(in=a) Practice.testgroup5(in=b) / repeated;&lt;BR /&gt;  by au fyear;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mmaxiu_0-1714505936383.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96062i5050525ED85DF00D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mmaxiu_0-1714505936383.png" alt="mmaxiu_0-1714505936383.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mmaxiu_1-1714506149355.png" style="width: 746px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96063i2D34242E8EC8FFC3/image-dimensions/746x318?v=v2" width="746" height="318" role="button" title="mmaxiu_1-1714506149355.png" alt="mmaxiu_1-1714506149355.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 19:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926521#M364603</guid>
      <dc:creator>mmaxiu</dc:creator>
      <dc:date>2024-04-30T19:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge a smaller dataset into a larger dataset with repetition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926524#M364604</link>
      <description>&lt;P&gt;No idea what "with repetition" means.&amp;nbsp; And the photographs of data don't help explain it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you just doing a simple 1 to Many merge?&amp;nbsp; Does the combination of AU and YEAR uniquely identify the observations in at least one of the datasets?&amp;nbsp; If so data step merge is what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to do a many to many merge?&amp;nbsp; If so then you probably want to use PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is something else then explain, with examples. And share your example data as text, not photographs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 20:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926524#M364604</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-30T20:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge a smaller dataset into a larger dataset with repetition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926527#M364605</link>
      <description>&lt;P&gt;Pictures are extremely poor ways to share data. We cannot write code against pictures. At least paste text. I am too lazy to retype pictures. Ideally, provide us with the data in data step format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The MERGE statement has no options behind a forward slash. Where did you get that REPEATED option from?&lt;BR /&gt;SAS® 9.4 and SAS® Viya® 3.5 Programming Documentation&lt;BR /&gt;DATA Step Statements -- MERGE Statement&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1i8w2bwu1fn5kn1gpxj18xttbb0.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1i8w2bwu1fn5kn1gpxj18xttbb0.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I don't see the problem.&lt;BR /&gt;The requested repetition is there automatically as the by-variables (merge keys) match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this and check the result (!) :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Practice.merged_testgroup;
  merge Practice.testgroup2 Practice.testgroup5;
  by au fyear;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 20:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926527#M364605</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-04-30T20:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge a smaller dataset into a larger dataset with repetition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926529#M364606</link>
      <description>&lt;P&gt;Hi, Tom.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply and the suggestions! Here's an example to clarify. Based on the tables above, I want to take the value of smallclient in row 1 of the smaller table and show its value for all combinations of au = 0 and fyear = 2011 in the larger table. So, the output I'm looking for in a merged table is for rows 1 through 15 from the larger table to have the variable smallclient show as zero for every single row. This would then be repeated for the whole larger table of 6841 rows.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 20:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926529#M364606</guid>
      <dc:creator>mmaxiu</dc:creator>
      <dc:date>2024-04-30T20:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge a smaller dataset into a larger dataset with repetition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926531#M364607</link>
      <description>&lt;P&gt;Thanks, Koen! I tried the code you suggested, but what happens is that the merged table only contains the same number of rows as the smaller table, not the larger one.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 20:20:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926531#M364607</guid>
      <dc:creator>mmaxiu</dc:creator>
      <dc:date>2024-04-30T20:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge a smaller dataset into a larger dataset with repetition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926533#M364608</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465588"&gt;@mmaxiu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, Tom.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your reply and the suggestions! Here's an example to clarify. Based on the tables above, I want to take the value of smallclient in row 1 of the smaller table and show its value for all combinations of au = 0 and fyear = 2011 in the larger table. So, the output I'm looking for in a merged table is for rows 1 through 15 from the larger table to have the variable smallclient show as zero for every single row. This would then be repeated for the whole larger table of 6841 rows.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is exactly what a simple MERGE will do.&amp;nbsp; As long as SMALLCLIENT does NOT already exist as a variable in the second table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
  input id lookup $;
cards;
1 A
2 B
3 C
;

data many ;
  input id other $;
cards;
1 X
1 Y
1 Z
2 W
4 V
;

data want;
  merge many one ;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    id    other    lookup

 1      1      X        A
 2      1      Y        A
 3      1      Z        A
 4      2      W        B
 5      3               C
 6      4      V
&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Apr 2024 20:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926533#M364608</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-30T20:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge a smaller dataset into a larger dataset with repetition?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926535#M364609</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465588"&gt;@mmaxiu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks, Koen! I tried the code you suggested, but what happens is that the merged table only contains the same number of rows as the smaller table, not the larger one.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Koen's code as posted could not subset the rows to be only the rows from the smaller table.&amp;nbsp; Please show the full log from running that step.&amp;nbsp; The log will show the actual code ran, the number of records read from each dataset, and the number of records written.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2024 20:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-a-smaller-dataset-into-a-larger-dataset-with/m-p/926535#M364609</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-04-30T20:36:01Z</dc:date>
    </item>
  </channel>
</rss>

