<?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 update a SAS dataset using another dataset on basis of a common field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267055#M52727</link>
    <description>&lt;P&gt;Here's an approach.&amp;nbsp; Assuming both data sets are first sorted by ID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;merge data_one (in=in1)&amp;nbsp; data_two (in=in2 rename=(v3-v5=w3-w5));&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;if in1;&lt;/P&gt;
&lt;P&gt;if in2 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; v3=w3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; v4=w4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; v5=w5;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop w3-w5;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Apr 2016 17:26:25 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-04-28T17:26:25Z</dc:date>
    <item>
      <title>How do I update a SAS dataset using another dataset on basis of a common field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267045#M52724</link>
      <description>&lt;P&gt;Hello, Could anyone help me on how to update observations in an existing SAS dataset, using another dataset. Like, I have 2 datasets :-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA Data_one;&lt;/P&gt;&lt;P&gt;input id prod $ v1 v2 v3 v4 v5;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;100 abc 1 0 0 0 0&amp;nbsp;&lt;/P&gt;&lt;P&gt;102 asd 1 1 0 0 0&lt;/P&gt;&lt;P&gt;105 0 1 0 0 0&lt;/P&gt;&lt;P&gt;100 pqr 1 0 0 0 0&amp;nbsp;&lt;/P&gt;&lt;P&gt;102 sdf 0 1 0 0 0&lt;/P&gt;&lt;P&gt;103 rty 1 1 0 0 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA Data_two;&lt;/P&gt;&lt;P&gt;input id v3 v4 v5;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;100 1 0 1&lt;/P&gt;&lt;P&gt;102 0 1 0&lt;/P&gt;&lt;P&gt;103 0 0 0&lt;/P&gt;&lt;P&gt;105 1 0 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the fields v3,v4,v5 of Data_one to be updated according to Data_two on the basis of the ID field. I tried using merge statement, but that updated only the first observation for each group. For ex. in Data_one, I want for ID 100 the fields should get updated as 1,0,1 under 'abc' as well as under 'pqr', and not only under 'abc'. Please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 17:15:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267045#M52724</guid>
      <dc:creator>PoojaP1</dc:creator>
      <dc:date>2016-04-28T17:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I update a SAS dataset using another dataset on basis of a common field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267048#M52725</link>
      <description>&lt;P&gt;Have you tried an update statement?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 17:20:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267048#M52725</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-28T17:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I update a SAS dataset using another dataset on basis of a common field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267051#M52726</link>
      <description>&lt;P&gt;Yes, I tried using that. But, it updated only the very first observation of each group of the BY variable. Like, for ID 100 it updated only the first observation and not the second one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help. Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 17:22:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267051#M52726</guid>
      <dc:creator>PoojaP1</dc:creator>
      <dc:date>2016-04-28T17:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I update a SAS dataset using another dataset on basis of a common field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267055#M52727</link>
      <description>&lt;P&gt;Here's an approach.&amp;nbsp; Assuming both data sets are first sorted by ID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;merge data_one (in=in1)&amp;nbsp; data_two (in=in2 rename=(v3-v5=w3-w5));&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;if in1;&lt;/P&gt;
&lt;P&gt;if in2 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; v3=w3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; v4=w4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; v5=w5;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop w3-w5;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 17:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267055#M52727</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-28T17:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I update a SAS dataset using another dataset on basis of a common field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267057#M52728</link>
      <description>&lt;P&gt;Can you have multiples in both files or only the first file?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 17:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267057#M52728</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-28T17:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I update a SAS dataset using another dataset on basis of a common field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267059#M52730</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;: No, only the first dataset contains multiples.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 17:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267059#M52730</guid>
      <dc:creator>PoojaP1</dc:creator>
      <dc:date>2016-04-28T17:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I update a SAS dataset using another dataset on basis of a common field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267061#M52731</link>
      <description>&lt;P&gt;You'll have to explicitly code it if you have multiples.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A data step or SQL will work. It can be a SQL join or an update.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a SQL join example, others have posted a data step solution that will work as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.id, a.prod, a.v1, a.v2, coalesce(b.v3, a.v3) as v3, coalesce(b.v4, a.v4) as v4, coalesce(b.v5, a.v5) as v5
from data_one as a
left join data_two as b
on a.id=b.id
order by 1,2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Apr 2016 17:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267061#M52731</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-28T17:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I update a SAS dataset using another dataset on basis of a common field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267063#M52732</link>
      <description>&lt;P&gt;Thanks a lot for your quick help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks to both of you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 17:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-update-a-SAS-dataset-using-another-dataset-on-basis-of/m-p/267063#M52732</guid>
      <dc:creator>PoojaP1</dc:creator>
      <dc:date>2016-04-28T17:42:48Z</dc:date>
    </item>
  </channel>
</rss>

