<?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 How do I merge two datasets in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-merge-two-datasets/m-p/882967#M39176</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have two datasets. One is the 'Combined' which includes application address, supply address and original address and other dataset is current address. I want to merge them and have all the four address type in one table. They both have same variables (columns) and I want to join using debt_code. I have tried Union but it doesn't work. Can you please suggest the best way to do it? I want to join all the records and then I will see how many debt_codes have missing address, name, etc and how many have values at least in one ad_type. Here is a sample data set and my code:&lt;/P&gt;
&lt;P&gt;Data Address; &lt;BR /&gt;infile cards expandtabs; &lt;BR /&gt;input debt_code Title $ Forename $ Surname $ DOB ad_address1 $ ad_address2 $ ad_address3 $ ad_address4 $ ad_address5 $ ad_postcode $ ad_type$; &lt;BR /&gt;datalines ; &lt;BR /&gt;119409498 Miss Anne Tait . Langmuir Kirkintilloch Glasgow Lanarkshire . G662PD AP&lt;BR /&gt;119409498 Miss Anne Tait . Langmuir Kirkintilloch Glasgow . . G662PD DB&lt;BR /&gt;119566768 Miss Anne Tait . Langmuir Kirkintilloch Glasgow . . G662PD DB&lt;BR /&gt;119566768 Miss Anne Tait . Langmuir Kirkintilloch Glasgow Lanarkshire . G662PD AP&lt;BR /&gt;113585517 Mr Tuncel Ibrahim . Broke London . . . E84SJ DB&lt;BR /&gt;117474056 Mr Lee Roberts . Warrior Leonards-On-sea East . . TN376BP SA&lt;BR /&gt;118829142 Mr Barry Miller . 193 Kingsknowe Edinburgh Midlothian . EH142ED DB&lt;BR /&gt;; &lt;BR /&gt;run; &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Combined_with_cur_add as
select *
from work.Combined
Union
select *
from work.current_address
where Combined.debt_code = Current_Address.debt_code; 
quit;
Error log:
29         proc sql;
30         create table Combined_with_cur_add as
31         select *
32         from work.Combined
33         Union
34         select *
35         from work.current_address
36         where Combined.debt_code = Current_Address.debt_code;
ERROR: Unresolved reference to table/correlation name Combined.
WARNING: A table has been extended with null columns to perform the UNION set operation.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
37         quit;
NOTE: The SAS System stopped processing this step because of errors.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Jun 2023 15:59:53 GMT</pubDate>
    <dc:creator>Sandeep77</dc:creator>
    <dc:date>2023-06-29T15:59:53Z</dc:date>
    <item>
      <title>How do I merge two datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-merge-two-datasets/m-p/882967#M39176</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have two datasets. One is the 'Combined' which includes application address, supply address and original address and other dataset is current address. I want to merge them and have all the four address type in one table. They both have same variables (columns) and I want to join using debt_code. I have tried Union but it doesn't work. Can you please suggest the best way to do it? I want to join all the records and then I will see how many debt_codes have missing address, name, etc and how many have values at least in one ad_type. Here is a sample data set and my code:&lt;/P&gt;
&lt;P&gt;Data Address; &lt;BR /&gt;infile cards expandtabs; &lt;BR /&gt;input debt_code Title $ Forename $ Surname $ DOB ad_address1 $ ad_address2 $ ad_address3 $ ad_address4 $ ad_address5 $ ad_postcode $ ad_type$; &lt;BR /&gt;datalines ; &lt;BR /&gt;119409498 Miss Anne Tait . Langmuir Kirkintilloch Glasgow Lanarkshire . G662PD AP&lt;BR /&gt;119409498 Miss Anne Tait . Langmuir Kirkintilloch Glasgow . . G662PD DB&lt;BR /&gt;119566768 Miss Anne Tait . Langmuir Kirkintilloch Glasgow . . G662PD DB&lt;BR /&gt;119566768 Miss Anne Tait . Langmuir Kirkintilloch Glasgow Lanarkshire . G662PD AP&lt;BR /&gt;113585517 Mr Tuncel Ibrahim . Broke London . . . E84SJ DB&lt;BR /&gt;117474056 Mr Lee Roberts . Warrior Leonards-On-sea East . . TN376BP SA&lt;BR /&gt;118829142 Mr Barry Miller . 193 Kingsknowe Edinburgh Midlothian . EH142ED DB&lt;BR /&gt;; &lt;BR /&gt;run; &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Combined_with_cur_add as
select *
from work.Combined
Union
select *
from work.current_address
where Combined.debt_code = Current_Address.debt_code; 
quit;
Error log:
29         proc sql;
30         create table Combined_with_cur_add as
31         select *
32         from work.Combined
33         Union
34         select *
35         from work.current_address
36         where Combined.debt_code = Current_Address.debt_code;
ERROR: Unresolved reference to table/correlation name Combined.
WARNING: A table has been extended with null columns to perform the UNION set operation.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
37         quit;
NOTE: The SAS System stopped processing this step because of errors.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 15:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-merge-two-datasets/m-p/882967#M39176</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-06-29T15:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I merge two datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-merge-two-datasets/m-p/882968#M39177</link>
      <description>&lt;P&gt;You are not JOINing the dataset.&amp;nbsp; Union will merely STACK the results of the two separate queries.&amp;nbsp; Because they are separate queries the second one knows nothing about the dataset mentioned in the first query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the purpose of the WHERE clause?&amp;nbsp; Why not just eliminate it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you mean to just keep the records from the second dataset that have ids that appear in the first dataset?&amp;nbsp; Then the WHERE clause of the second query should look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select *
from work.current_address
where Current_Address.debt_code in (select Combined.debt_code from work.Combined)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 16:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-merge-two-datasets/m-p/882968#M39177</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-29T16:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I merge two datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-merge-two-datasets/m-p/882969#M39178</link>
      <description>&lt;P&gt;Much easier to do with SAS code than SQL code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Combined_with_cur_add ;
  set Combined&amp;nbsp;Current_Address;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Jun 2023 16:21:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-merge-two-datasets/m-p/882969#M39178</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-29T16:21:22Z</dc:date>
    </item>
  </channel>
</rss>

