<?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: Merging datasets with different number of observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-different-number-of-observations/m-p/886840#M350415</link>
    <description>&lt;P&gt;Sorry, I'm not understanding. You have variables AGE1 AGE2 and AGE3, then you talk about merging data sets AGE1 AGE2 and AGE3. That doesn't seem right.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show us (a portion of) all the data sets involved here. Please provide data as WORKING data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;).&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jul 2023 16:55:53 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-07-28T16:55:53Z</dc:date>
    <item>
      <title>Merging datasets with different number of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-different-number-of-observations/m-p/886839#M350414</link>
      <description>&lt;P&gt;Hi! I want to merge datasets by ID. Each dataset has different ages. I would like to get a merged dataset that looks like this:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;age1&lt;/TD&gt;&lt;TD&gt;age2&lt;/TD&gt;&lt;TD&gt;age3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt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&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;As you can see, for example for ID=1, it has two different observations for age2 and only one observation for age1. However, after merging, the value for age1 repeats. I would like to avoid that, since I want to calculate frequencies per variable and having two observations with the value 12 for ID is not correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 16:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-different-number-of-observations/m-p/886839#M350414</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-07-28T16:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with different number of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-different-number-of-observations/m-p/886840#M350415</link>
      <description>&lt;P&gt;Sorry, I'm not understanding. You have variables AGE1 AGE2 and AGE3, then you talk about merging data sets AGE1 AGE2 and AGE3. That doesn't seem right.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show us (a portion of) all the data sets involved here. Please provide data as WORKING data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;).&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 16:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-different-number-of-observations/m-p/886840#M350415</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-28T16:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with different number of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-different-number-of-observations/m-p/886844#M350417</link>
      <description>Hi! Sorry, the datasets names are different. I am aware of that. Just changed the names to publish here.</description>
      <pubDate>Fri, 28 Jul 2023 17:01:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-different-number-of-observations/m-p/886844#M350417</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-07-28T17:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with different number of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-different-number-of-observations/m-p/886849#M350420</link>
      <description>&lt;P&gt;Please read my request in my previous message, where I said:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please show us (a portion of) &lt;FONT color="#FF0000"&gt;all&lt;/FONT&gt; the data sets involved here. Please provide data as WORKING data step code (&lt;/SPAN&gt;&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self" rel="nofollow noopener noreferrer"&gt;examples and instructions&lt;/A&gt;&lt;SPAN&gt;).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 17:06:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-different-number-of-observations/m-p/886849#M350420</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-28T17:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with different number of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-different-number-of-observations/m-p/886872#M350430</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226521"&gt;@ANKH1&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can reset the age variables to missing by inserting&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call missing(ID, of age1-age3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before the MERGE statement (variable ID is included optionally just to maintain variable order).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I wouldn't merge the datasets this way with the intention "&lt;SPAN&gt;to calculate frequencies per variable."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226521"&gt;@ANKH1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;(...) having two observations with the value 12 for ID is not correct.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Note that&amp;nbsp;having an observation with &lt;EM&gt;missing&lt;/EM&gt; &lt;FONT face="courier new,courier"&gt;age1&lt;/FONT&gt; for ID 1 is actually not correct either.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Frequencies could be calculated from the &lt;EM&gt;original&lt;/EM&gt; datasets or after &lt;EM&gt;interleaving&lt;/EM&gt; them, e.g., like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ages_all;
set age1(rename=(age1=age) in=in1)
    age2(rename=(age2=age) in=in2)
    age3(rename=(age3=age) in=in3);
by id;
ds=in1+2*in2+3*in3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;(Instead of RENAME= and IN= dataset options you could use the COALESCE function and the INDSNAME= option of the SET statement, respectively.)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 17:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-different-number-of-observations/m-p/886872#M350430</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-07-28T17:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets with different number of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-different-number-of-observations/m-p/886915#M350449</link>
      <description>&lt;P&gt;Thank you so much! The output was what I needed!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 22:22:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-with-different-number-of-observations/m-p/886915#M350449</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2023-07-28T22:22:33Z</dc:date>
    </item>
  </channel>
</rss>

