<?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 How to combine datasets that have different # of observation within each ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-datasets-that-have-different-of-observation/m-p/967191#M376302</link>
    <description>&lt;P&gt;Hi Dear SAS Pros,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 2 or more datasets as follows:&lt;/P&gt;
&lt;P&gt;data db1;&lt;/P&gt;
&lt;P&gt;input id V1 ;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;1 0.5&lt;BR /&gt;1 0.6&lt;BR /&gt;1 0.7&lt;BR /&gt;1 0.8&lt;/P&gt;
&lt;P&gt;2 0.7&lt;BR /&gt;2 0.5&lt;/P&gt;
&lt;P&gt;3 0.4&lt;BR /&gt;3 0.8&lt;/P&gt;
&lt;P&gt;4 0.6&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;data db2;&lt;/P&gt;
&lt;P&gt;input id V2 ;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;1 2.5&lt;BR /&gt;1 2.6&lt;/P&gt;
&lt;P&gt;2 2.7&lt;BR /&gt;2 2.5&lt;BR /&gt;2 2.6&lt;/P&gt;
&lt;P&gt;4 2.6&lt;BR /&gt;4 2.1&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what I want for output is as follows:&lt;/P&gt;
&lt;P&gt;id V1 V2&lt;BR /&gt;1 0.5 2.5 &lt;BR /&gt;1 0.6 2.6&lt;BR /&gt;1 0.7&amp;nbsp; .&lt;BR /&gt;1 0.8&amp;nbsp; .&lt;/P&gt;
&lt;P&gt;2 0.7 2.7&lt;BR /&gt;2 0.5 2.5&lt;BR /&gt;2&amp;nbsp; .&amp;nbsp; 2.6&lt;/P&gt;
&lt;P&gt;3 0.4&amp;nbsp; .&lt;BR /&gt;3 0.8&amp;nbsp; .&lt;/P&gt;
&lt;P&gt;4 0.6 2.6&lt;BR /&gt;4&amp;nbsp; .&amp;nbsp; 2.1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for any advice or help.&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;C&lt;/P&gt;</description>
    <pubDate>Thu, 22 May 2025 03:57:01 GMT</pubDate>
    <dc:creator>CynthiaWei</dc:creator>
    <dc:date>2025-05-22T03:57:01Z</dc:date>
    <item>
      <title>How to combine datasets that have different # of observation within each ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-datasets-that-have-different-of-observation/m-p/967191#M376302</link>
      <description>&lt;P&gt;Hi Dear SAS Pros,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 2 or more datasets as follows:&lt;/P&gt;
&lt;P&gt;data db1;&lt;/P&gt;
&lt;P&gt;input id V1 ;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;1 0.5&lt;BR /&gt;1 0.6&lt;BR /&gt;1 0.7&lt;BR /&gt;1 0.8&lt;/P&gt;
&lt;P&gt;2 0.7&lt;BR /&gt;2 0.5&lt;/P&gt;
&lt;P&gt;3 0.4&lt;BR /&gt;3 0.8&lt;/P&gt;
&lt;P&gt;4 0.6&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;data db2;&lt;/P&gt;
&lt;P&gt;input id V2 ;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;1 2.5&lt;BR /&gt;1 2.6&lt;/P&gt;
&lt;P&gt;2 2.7&lt;BR /&gt;2 2.5&lt;BR /&gt;2 2.6&lt;/P&gt;
&lt;P&gt;4 2.6&lt;BR /&gt;4 2.1&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what I want for output is as follows:&lt;/P&gt;
&lt;P&gt;id V1 V2&lt;BR /&gt;1 0.5 2.5 &lt;BR /&gt;1 0.6 2.6&lt;BR /&gt;1 0.7&amp;nbsp; .&lt;BR /&gt;1 0.8&amp;nbsp; .&lt;/P&gt;
&lt;P&gt;2 0.7 2.7&lt;BR /&gt;2 0.5 2.5&lt;BR /&gt;2&amp;nbsp; .&amp;nbsp; 2.6&lt;/P&gt;
&lt;P&gt;3 0.4&amp;nbsp; .&lt;BR /&gt;3 0.8&amp;nbsp; .&lt;/P&gt;
&lt;P&gt;4 0.6 2.6&lt;BR /&gt;4&amp;nbsp; .&amp;nbsp; 2.1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for any advice or help.&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;C&lt;/P&gt;</description>
      <pubDate>Thu, 22 May 2025 03:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-datasets-that-have-different-of-observation/m-p/967191#M376302</guid>
      <dc:creator>CynthiaWei</dc:creator>
      <dc:date>2025-05-22T03:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine datasets that have different # of observation within each ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-datasets-that-have-different-of-observation/m-p/967192#M376303</link>
      <description>&lt;P&gt;A normal MERGE will leave the last value read in from a "short" dataset unchanged in a BY group.&amp;nbsp; That is the reason that it works properly to do a 1 to MANY merge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your input you would get.&lt;/P&gt;
&lt;PRE&gt;Obs    id     V1     V2

  1     1    0.5    2.5
  2     1    0.6    2.6
  3     1    0.7    2.6
  4     1    0.8    2.6
  5     2    0.7    2.7
  6     2    0.5    2.5
  7     2    0.5    2.6
  8     3    0.4     .
  9     3    0.8     .
 10     4    0.6    2.6
 11     4    0.6    2.1
&lt;/PRE&gt;
&lt;P&gt;If you don't want the short datasets' values retained then add an explicit OUTPUT statement and a CALL MISSING() statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge db1 db2;
  by id;
  output;
  call missing(of _all_);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    id     V1     V2

  1     1    0.5    2.5
  2     1    0.6    2.6
  3     1    0.7     .
  4     1    0.8     .
  5     2    0.7    2.7
  6     2    0.5    2.5
  7     2     .     2.6
  8     3    0.4     .
  9     3    0.8     .
 10     4    0.6    2.6
 11     4     .     2.1
&lt;/PRE&gt;
&lt;P&gt;NOTE: I did not attempt to download your attachment.&amp;nbsp; If its contents are important then include it in the body of your message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Use the Insert SAS Code and/or the Insert Code icons to get pop-up windows where you can paste in (or type or edit) lines of code or data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 May 2025 04:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-datasets-that-have-different-of-observation/m-p/967192#M376303</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-05-22T04:22:17Z</dc:date>
    </item>
  </channel>
</rss>

