<?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 Proc SQL, compare two datasets and keep one variable from beeing compared in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-compare-two-datasets-and-keep-one-variable-from-beeing/m-p/808603#M318844</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need to find differences between two datasets. I need to leave out one variable but need it from dataset2 in the dataset created..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So find the difference between rows in all columns except one column that will always be different and then keep that column in the created table with the data from one of the compared tables. The column I dont want to compare contains the date the dataset was created and I need to keep the date from one of the datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code I have that works fine when comparing all columns. This code is applied on many different tables with different amount of columns. The column I want to ignore in the compare but keep in the result will always have the same name, DATE:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data data_today;
input employee $ salary $ date $;
datalines;
Smith 40000 20220419
Cool 00004 20220419&lt;BR /&gt;Me 000055 20220419
;
run;

data data_yesterday;
input employee $ salary $ date $;
datalines;
Smith 40000 20220418
Cool 00003 20220418&lt;BR /&gt;Me 000055 20220419
;
run;

proc sql;
create table Help as
select * from data_today
except
select * from data_yesterday;
quit;&lt;BR /&gt;&lt;BR /&gt;Result wanted:&lt;BR /&gt;Cool 00004 20220419&lt;/PRE&gt;&lt;P&gt;The result should only contain 'Cool' because she has a different salary. Smith or Me should not be included because it's only the date that is different:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is applied on many different tables so I have to use select * , but the date column will always have the same name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Apr 2022 15:49:36 GMT</pubDate>
    <dc:creator>ModernaMattias</dc:creator>
    <dc:date>2022-04-19T15:49:36Z</dc:date>
    <item>
      <title>Proc SQL, compare two datasets and keep one variable from beeing compared</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-compare-two-datasets-and-keep-one-variable-from-beeing/m-p/808603#M318844</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need to find differences between two datasets. I need to leave out one variable but need it from dataset2 in the dataset created..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So find the difference between rows in all columns except one column that will always be different and then keep that column in the created table with the data from one of the compared tables. The column I dont want to compare contains the date the dataset was created and I need to keep the date from one of the datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code I have that works fine when comparing all columns. This code is applied on many different tables with different amount of columns. The column I want to ignore in the compare but keep in the result will always have the same name, DATE:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data data_today;
input employee $ salary $ date $;
datalines;
Smith 40000 20220419
Cool 00004 20220419&lt;BR /&gt;Me 000055 20220419
;
run;

data data_yesterday;
input employee $ salary $ date $;
datalines;
Smith 40000 20220418
Cool 00003 20220418&lt;BR /&gt;Me 000055 20220419
;
run;

proc sql;
create table Help as
select * from data_today
except
select * from data_yesterday;
quit;&lt;BR /&gt;&lt;BR /&gt;Result wanted:&lt;BR /&gt;Cool 00004 20220419&lt;/PRE&gt;&lt;P&gt;The result should only contain 'Cool' because she has a different salary. Smith or Me should not be included because it's only the date that is different:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is applied on many different tables so I have to use select * , but the date column will always have the same name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2022 15:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-compare-two-datasets-and-keep-one-variable-from-beeing/m-p/808603#M318844</guid>
      <dc:creator>ModernaMattias</dc:creator>
      <dc:date>2022-04-19T15:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL, compare two datasets and keep one variable from beeing compared</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-compare-two-datasets-and-keep-one-variable-from-beeing/m-p/808616#M318849</link>
      <description>&lt;P&gt;Is this what you're looking for?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as
    select t.*
    from data_today t
    left join data_yesterday y
        on t.employee = y.employee
        and t.salary = y.salary
    where y.employee is null
    ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, are all the dates in your&amp;nbsp;&lt;STRONG&gt;data_yesterday&amp;nbsp;&lt;/STRONG&gt;table all supposed to be 2022041&lt;STRONG&gt;8&lt;/STRONG&gt;? I presume so; however, your provided data has one row with 2022041&lt;STRONG&gt;9&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2022 16:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-compare-two-datasets-and-keep-one-variable-from-beeing/m-p/808616#M318849</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2022-04-19T16:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL, compare two datasets and keep one variable from beeing compared</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-compare-two-datasets-and-keep-one-variable-from-beeing/m-p/808640#M318855</link>
      <description>&lt;P&gt;Use the DROP dataset option to exclude the dates and then a NATURAL JOIN to bring the date back from data_today. This works for any number of variables, as long as you don't have duplicates in data_today.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Help as
select * from
(select * from data_today(drop=date)
 except
 select * from data_yesterday(drop=date))
natural join data_today;
quit;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2022 18:04:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-compare-two-datasets-and-keep-one-variable-from-beeing/m-p/808640#M318855</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-04-19T18:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL, compare two datasets and keep one variable from beeing compared</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-compare-two-datasets-and-keep-one-variable-from-beeing/m-p/808756#M318900</link>
      <description>Thanks for all your help! Really appreciate it!</description>
      <pubDate>Wed, 20 Apr 2022 08:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-compare-two-datasets-and-keep-one-variable-from-beeing/m-p/808756#M318900</guid>
      <dc:creator>ModernaMattias</dc:creator>
      <dc:date>2022-04-20T08:56:02Z</dc:date>
    </item>
  </channel>
</rss>

