<?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 Finding the maximum date from 3 variables from 3 datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-maximum-date-from-3-variables-from-3-datasets/m-p/640782#M190943</link>
    <description>&lt;P&gt;Hey guys... my latest hurdle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have (so far) 3 data sets that have a variable called "updated_date".&amp;nbsp; This is the date the record for that dataset was last updated.&amp;nbsp; When joining each dataset by id, I need to be able to choose the maximum updated_date for a record depending on which dataset it is in.&amp;nbsp; Here is what I have so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select 
    id
    , &amp;lt;max updated date between d1.updated_date, d2.updated_date, d3.updated_date&amp;gt;
from dataset1 d1
inner join dataset2 d2 on d2.id = d1.id
inner join dataset3 d3 on d3.id = d1.id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would prefer not using a case statement unless it is the only way because I will most likely be adding more tables that will also have their own updated_date.&amp;nbsp; After some research, I have seen some posts that talk about using arrays in a data step to do this, but I can't determine how that would be done across multiple data sets.&amp;nbsp; The post I am referring to is this one: &lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-Get-Maximum-Row-s-Value-with-its-Name-of-Variable-into/td-p/326629" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-Get-Maximum-Row-s-Value-with-its-Name-of-Variable-into/td-p/326629&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Apr 2020 17:07:25 GMT</pubDate>
    <dc:creator>elwayfan446</dc:creator>
    <dc:date>2020-04-17T17:07:25Z</dc:date>
    <item>
      <title>Finding the maximum date from 3 variables from 3 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-maximum-date-from-3-variables-from-3-datasets/m-p/640782#M190943</link>
      <description>&lt;P&gt;Hey guys... my latest hurdle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have (so far) 3 data sets that have a variable called "updated_date".&amp;nbsp; This is the date the record for that dataset was last updated.&amp;nbsp; When joining each dataset by id, I need to be able to choose the maximum updated_date for a record depending on which dataset it is in.&amp;nbsp; Here is what I have so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select 
    id
    , &amp;lt;max updated date between d1.updated_date, d2.updated_date, d3.updated_date&amp;gt;
from dataset1 d1
inner join dataset2 d2 on d2.id = d1.id
inner join dataset3 d3 on d3.id = d1.id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would prefer not using a case statement unless it is the only way because I will most likely be adding more tables that will also have their own updated_date.&amp;nbsp; After some research, I have seen some posts that talk about using arrays in a data step to do this, but I can't determine how that would be done across multiple data sets.&amp;nbsp; The post I am referring to is this one: &lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-Get-Maximum-Row-s-Value-with-its-Name-of-Variable-into/td-p/326629" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-Get-Maximum-Row-s-Value-with-its-Name-of-Variable-into/td-p/326629&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 17:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-maximum-date-from-3-variables-from-3-datasets/m-p/640782#M190943</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-04-17T17:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the maximum date from 3 variables from 3 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-maximum-date-from-3-variables-from-3-datasets/m-p/640786#M190945</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select 
    id
    , max(d1.updated_date, d2.updated_date, d3.updated_date) as max_updated
from dataset1 d1
inner join dataset2 d2 on d2.id = d1.id
inner join dataset3 d3 on d3.id = d1.id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Apr 2020 17:22:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-maximum-date-from-3-variables-from-3-datasets/m-p/640786#M190945</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-04-17T17:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the maximum date from 3 variables from 3 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-maximum-date-from-3-variables-from-3-datasets/m-p/640788#M190946</link>
      <description>&lt;P&gt;SAS has a MAX(,) function that is different than the MAX() aggregate function of SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select 
    id
    , max(d1.updated_date, d2.updated_date, d3.updated_date) as date format=date9.
from dataset1 d1
inner join dataset2 d2 on d2.id = d1.id
inner join dataset3 d3 on d3.id = d1.id
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 17:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-maximum-date-from-3-variables-from-3-datasets/m-p/640788#M190946</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-17T17:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the maximum date from 3 variables from 3 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-maximum-date-from-3-variables-from-3-datasets/m-p/640791#M190947</link>
      <description>Well, that was easy. I wasn't using MAX because I thought I was going to have to group by every other variable in my query (there will be a lot of them). I didn't realize there was a MAX function that wasn't an aggregate. Thanks so much!</description>
      <pubDate>Fri, 17 Apr 2020 17:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-maximum-date-from-3-variables-from-3-datasets/m-p/640791#M190947</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-04-17T17:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the maximum date from 3 variables from 3 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-maximum-date-from-3-variables-from-3-datasets/m-p/640796#M190948</link>
      <description>&lt;P&gt;Another option could be the LARGEST function, which you specify which of the order (1= first or largest value, 2= 2nd largest and so on)&lt;/P&gt;
&lt;PRE&gt;data example;
   input x1-x3;
datalines;
1 3 47
18 6 0
;

proc sql;
   select largest(1,x1,x2,x3) as maxvalue
   from example;
run;&lt;/PRE&gt;
&lt;P&gt;Which may be helpful if you do use a group clause.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 17:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-maximum-date-from-3-variables-from-3-datasets/m-p/640796#M190948</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-17T17:37:05Z</dc:date>
    </item>
  </channel>
</rss>

