<?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 add variables from a different dataset by ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-variables-from-a-different-dataset-by-ID/m-p/793729#M254439</link>
    <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input ID (drug date_of_claim ATC)($);
datalines;
1 a b c
1 e f g
2 x y z
3 z r t
3 r t g
;

data b;
input ID (start_insurance end_insurance)(:date9.);
format start_insurance end_insurance date9.;
datalines;
1 01feb2022 02feb2022
2 03feb2022 04feb2022
;

data want;
   merge a b;
   by ID;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 01 Feb 2022 11:00:18 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-02-01T11:00:18Z</dc:date>
    <item>
      <title>How to add variables from a different dataset by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-variables-from-a-different-dataset-by-ID/m-p/793724#M254438</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets, and I want to add variables from 1 dataset to the other.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Dataset_A&lt;/STRONG&gt; has several lines per patient ID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID drug date_of_claim ATC&lt;/P&gt;&lt;P&gt;1 a b c&lt;/P&gt;&lt;P&gt;1 e f g&lt;/P&gt;&lt;P&gt;2 x y z&lt;/P&gt;&lt;P&gt;3 z r t&lt;/P&gt;&lt;P&gt;3 r t g&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Dataset_B&lt;/STRONG&gt; has 1 line per ID&lt;/P&gt;&lt;P&gt;ID start_insurance end_insurance&lt;/P&gt;&lt;P&gt;1 date1 date2&lt;/P&gt;&lt;P&gt;2 date3 date4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to add the two varibales 'start_insurance' and 'end_insurance' from Dataset_B to Dataset_A, in a ways that every line in Dataset_A will have values for the dates.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure how to go about this, so any input is very welcome.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks very much in advance, Julia&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 10:56:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-variables-from-a-different-dataset-by-ID/m-p/793724#M254438</guid>
      <dc:creator>jspoend</dc:creator>
      <dc:date>2022-02-01T10:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to add variables from a different dataset by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-variables-from-a-different-dataset-by-ID/m-p/793729#M254439</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input ID (drug date_of_claim ATC)($);
datalines;
1 a b c
1 e f g
2 x y z
3 z r t
3 r t g
;

data b;
input ID (start_insurance end_insurance)(:date9.);
format start_insurance end_insurance date9.;
datalines;
1 01feb2022 02feb2022
2 03feb2022 04feb2022
;

data want;
   merge a b;
   by ID;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Feb 2022 11:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-variables-from-a-different-dataset-by-ID/m-p/793729#M254439</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-02-01T11:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to add variables from a different dataset by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-variables-from-a-different-dataset-by-ID/m-p/793736#M254445</link>
      <description>&lt;P&gt;You won't be able to get values where you have no match in B, but you can also use the hash method I showed in your other thread (using the datasets provided by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set a;
if _n_ = 1
then do;
  format start_insurance end_insurance date9.;
  declare hash b (dataset:"b");
  b.definekey("id");
  b.definedata("start_insurance","end_insurance");
  b.definedone();
end;
if b.find() ne 0
then do;
  start_insurance = .;
  end_insurance = .;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Feb 2022 11:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-variables-from-a-different-dataset-by-ID/m-p/793736#M254445</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-01T11:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to add variables from a different dataset by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-variables-from-a-different-dataset-by-ID/m-p/793738#M254447</link>
      <description>&lt;P&gt;Dear Kurt,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for the second time today, your command worked perfectly again, and I will know how to adjust it now as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a great day, Julia&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 12:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-variables-from-a-different-dataset-by-ID/m-p/793738#M254447</guid>
      <dc:creator>jspoend</dc:creator>
      <dc:date>2022-02-01T12:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to add variables from a different dataset by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-variables-from-a-different-dataset-by-ID/m-p/793739#M254448</link>
      <description>Hi Peter,&lt;BR /&gt;Thanks a lot for sending this, I've tried with merge before, but I was worried it would overwrite anything. But I guess it should be fine if there are no overlapping variables.&lt;BR /&gt;&lt;BR /&gt;Many thanks, Julia</description>
      <pubDate>Tue, 01 Feb 2022 12:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-variables-from-a-different-dataset-by-ID/m-p/793739#M254448</guid>
      <dc:creator>jspoend</dc:creator>
      <dc:date>2022-02-01T12:37:16Z</dc:date>
    </item>
  </channel>
</rss>

