<?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 combine three datasets with same variables in SAS? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-three-datasets-with-same-variables-in-SAS/m-p/654045#M196463</link>
    <description>&lt;P&gt;Use the UPDATE statement instead of the MERGE statement.&amp;nbsp; That is designed for transactions so missing values do not change the value.&lt;/P&gt;
&lt;P&gt;It needs two datasets to work.&amp;nbsp; The first is the source and the second are the transactions.&amp;nbsp; You could either do it in two steps.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   update data1 date2;
   by A;
run;
data want;
   update want date3;
   by A;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or first combine the datasets into one and then use that as both the source and transaction datasets.&amp;nbsp; To save temporary disk space and perhaps time you could use a datastep view to do the combining.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all / view=all;
   set data1-data3;
   by A;
run;
data want ;
   update all(obs=0) all;
   by A;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 07 Jun 2020 17:26:31 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-06-07T17:26:31Z</dc:date>
    <item>
      <title>How to combine three datasets with same variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-three-datasets-with-same-variables-in-SAS/m-p/654042#M196461</link>
      <description>&lt;P&gt;Hi, I have three datasets,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data1 
A   B  C  D
1   8  7  9
2   0  .  .
3   .  .  .

data2
A   B  C   D
1   8  .   .
2   0  5   0
3   .  .   .

data3
A   B  C  D
1   8  .  .
2   0  .  .
3   .  7  4&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need to combine these three datasets keeping A, B the same and combining C and D variables.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;All 
A   B  C  D
1   8  7  9
2   0  5  0
3   .  7  4&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am using merge, but it does not produce what I want:&lt;/P&gt;&lt;PRE&gt;data all;
 merge data1 data2 data3;
run;&lt;/PRE&gt;&lt;P&gt;Any ideas how can I perform this action?&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2020 16:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-three-datasets-with-same-variables-in-SAS/m-p/654042#M196461</guid>
      <dc:creator>ph6</dc:creator>
      <dc:date>2020-06-07T16:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine three datasets with same variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-three-datasets-with-same-variables-in-SAS/m-p/654044#M196462</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; This is an instance where I would probably use an UPDATE statement. With the UPDATEMODE=MISSINGCHECK option, you can make sure that nothing gets overwritten by the missings in DATA2 and DATA3.&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1 ;
infile datalines;
input A   B  C  D;
datalines;
1   8  7  9
2   0  .  .
3   .  .  .
;
run;

data data2;
infile datalines;
input A   B  C  D;
datalines;
1   8  .   .
2   0  5   0
3   .  .   .
;
run;

data data3;
infile datalines;
input A   B  C  D;
datalines;
1   8  .  .
2   0  .  .
3   .  7  4
;
run;

** put all update data in one file;
data allupdate;
  set data2 data3;
run;
  
proc sort data=allupdate;
by a;
run;
  
data final;
  update data1 allupdate updatemode=missingcheck;
  by a;
run;

proc print data=final;
title 'After applying all updates';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(modified to include by a statement in UPDATE program)&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2020 00:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-three-datasets-with-same-variables-in-SAS/m-p/654044#M196462</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-06-09T00:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine three datasets with same variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-three-datasets-with-same-variables-in-SAS/m-p/654045#M196463</link>
      <description>&lt;P&gt;Use the UPDATE statement instead of the MERGE statement.&amp;nbsp; That is designed for transactions so missing values do not change the value.&lt;/P&gt;
&lt;P&gt;It needs two datasets to work.&amp;nbsp; The first is the source and the second are the transactions.&amp;nbsp; You could either do it in two steps.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   update data1 date2;
   by A;
run;
data want;
   update want date3;
   by A;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or first combine the datasets into one and then use that as both the source and transaction datasets.&amp;nbsp; To save temporary disk space and perhaps time you could use a datastep view to do the combining.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all / view=all;
   set data1-data3;
   by A;
run;
data want ;
   update all(obs=0) all;
   by A;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2020 17:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-three-datasets-with-same-variables-in-SAS/m-p/654045#M196463</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-07T17:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine three datasets with same variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-three-datasets-with-same-variables-in-SAS/m-p/654046#M196464</link>
      <description>&lt;P&gt;Some questions:&lt;/P&gt;
&lt;P&gt;Do the values of the combination of A and B variables have duplicate values in ANY of the data sets?&lt;/P&gt;
&lt;P&gt;If so you will need to provide some actual rules of which records get which results.&lt;/P&gt;
&lt;P&gt;Second, if the variables C and D have values in more than one set which particular data set's value should be kept?&lt;/P&gt;
&lt;P&gt;Such as with the following, what would be the rule to keep which value (NOT and example, the RULE for selecting)&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2020 17:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-three-datasets-with-same-variables-in-SAS/m-p/654046#M196464</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-07T17:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine three datasets with same variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-three-datasets-with-same-variables-in-SAS/m-p/654050#M196466</link>
      <description>It works, but I needed to put by a also in the update statement. Thank you!</description>
      <pubDate>Sun, 07 Jun 2020 17:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-three-datasets-with-same-variables-in-SAS/m-p/654050#M196466</guid>
      <dc:creator>ph6</dc:creator>
      <dc:date>2020-06-07T17:47:38Z</dc:date>
    </item>
  </channel>
</rss>

