<?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 do I merge matched and main data sets in SAS? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272067#M58331</link>
    <description>&lt;P&gt;Easiest for me is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table want as
   select dataset1.*, dataset2.*
   from dataset1 left join dataset2 
        on dataset1.Caseid = Dataset2.Id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This may reorder your data if the caseids aren't sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 May 2016 17:58:31 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-05-20T17:58:31Z</dc:date>
    <item>
      <title>How do I merge matched and main data sets in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272048#M58330</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need help in merging two SAS data sets:&lt;/P&gt;
&lt;P&gt;(1) data set 1 (matched cases and controls): cases&amp;nbsp;&amp;amp;&amp;nbsp;controls matched 1:2 on age groups, chemo, and radiation&lt;/P&gt;
&lt;P&gt;(2) data set 2 (main): main data set containing all patients and their characteristics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data set 1 looks like this, where two rows represent one pair (case and its matched control):&lt;/P&gt;
&lt;P&gt;caseid controlid agegrp chemo rad num&lt;BR /&gt;0001 &amp;nbsp; 00052 &amp;nbsp; &amp;nbsp; 45+ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;0001 &amp;nbsp; 00082 &amp;nbsp; &amp;nbsp; 45+ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;0002&amp;nbsp; &amp;nbsp;00045&amp;nbsp; &amp;nbsp; 25-30 &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;0002&amp;nbsp; &amp;nbsp;00036&amp;nbsp; &amp;nbsp; 25-30 &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data set 2 looks like this (main pool of patients with baseline characteristics):&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stage &amp;nbsp;&amp;nbsp;er&amp;nbsp;&amp;nbsp; pr &amp;nbsp; &amp;nbsp;status&lt;BR /&gt;0001 &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 1&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;0002&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I merge data set 1 with the data set 2 to incorporate the baseline characteristics of patients?&lt;/P&gt;
&lt;P&gt;I would want to keep the same format as in the dataset 1 (two rows for one pair).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help!&lt;/P&gt;
&lt;P&gt;Tony&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 17:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272048#M58330</guid>
      <dc:creator>JD</dc:creator>
      <dc:date>2016-05-20T17:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I merge matched and main data sets in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272067#M58331</link>
      <description>&lt;P&gt;Easiest for me is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table want as
   select dataset1.*, dataset2.*
   from dataset1 left join dataset2 
        on dataset1.Caseid = Dataset2.Id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This may reorder your data if the caseids aren't sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 17:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272067#M58331</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-20T17:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I merge matched and main data sets in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272069#M58332</link>
      <description>&lt;P&gt;Assuming both of your data sets are sorted, you could try a simple merge:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;merge dataset1 dataset2 (rename=(id=caseid));&lt;/P&gt;
&lt;P&gt;by caseid;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That might be what you are looking for. &amp;nbsp;But even if it isn't, it would give you a starting point to describe how it is different from what you want.&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 18:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272069#M58332</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-20T18:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I merge matched and main data sets in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272083#M58333</link>
      <description>&lt;P&gt;Thanks, Astounding and Ballard!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I dont think i properly explained this :smileyhappy :).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By merging the two dataset, I want to create a final dataset which would contain characteristics or cases and their matched controls.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since I have two controls per case, my final dataset should contain the sets of matched pairs. For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;row 1 &amp;nbsp; &amp;nbsp; case &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;characteristics of this case in the next columns&lt;/P&gt;
&lt;P&gt;row 2 &amp;nbsp; &amp;nbsp; control &amp;nbsp; &amp;nbsp;characteristics of this control in the next columns&lt;/P&gt;
&lt;P&gt;row 3 &amp;nbsp; &amp;nbsp; control &amp;nbsp; &amp;nbsp;characteristics of this control in the next column&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So these three rows make one set of matched case with its controls.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 18:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272083#M58333</guid>
      <dc:creator>JD</dc:creator>
      <dc:date>2016-05-20T18:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I merge matched and main data sets in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272086#M58334</link>
      <description>&lt;P&gt;For that, you will have to spell out exactly which variables you want and what values they should take on for each of your rows. &amp;nbsp;SAS forces you to keep all variables for all rows. &amp;nbsp;Just give an example for one ID (3 rows) ... that should be enough.&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 18:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272086#M58334</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-20T18:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I merge matched and main data sets in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272088#M58335</link>
      <description>&lt;P&gt;Did you try the code?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you have 3 rows per case when you had 2 before?&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 18:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272088#M58335</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-20T18:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I merge matched and main data sets in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272119#M58338</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set dataset2 (in=in1)
       dataset1 
   ;
   if in1 then type='Case';
   else type='Control';
run;
proc sort data=want;
  by id type;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 May 2016 19:51:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-merge-matched-and-main-data-sets-in-SAS/m-p/272119#M58338</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-20T19:51:02Z</dc:date>
    </item>
  </channel>
</rss>

