<?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 add a statement to pull max date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836198#M36036</link>
    <description>&lt;P&gt;How would I write that in my code exactly?&amp;nbsp; This is not working unfortunately:&lt;/P&gt;&lt;PRE&gt;Proc Sql;
Create Table A As
Select Distinct
A.'ID'n,
B.'ITA ID'n,
B. max('Approval Date'n) as 'LatestApprovalDate'n,
B.'Due Date'n,
B.'Status'n,
B.'Completion Date'n
From FolderName.ID as A
inner join FolderName.ITA as B
on A.'ID'n = B.'ID'n
Order by 'ID'n
;
Quit&lt;/PRE&gt;</description>
    <pubDate>Fri, 30 Sep 2022 19:27:41 GMT</pubDate>
    <dc:creator>squeakums</dc:creator>
    <dc:date>2022-09-30T19:27:41Z</dc:date>
    <item>
      <title>How to add a statement to pull max date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836179#M36030</link>
      <description>&lt;P&gt;How would I write in the code to pull the max Open date in this code? Also, I think I'm writing this correct. I get confused about the joines. But, the ID file has all of the ID's and the ITA file doesn't but I want to pull in the details to the ID file. Is an inner join the correct way to do this or should it be a left join, center or right join?&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Proc Sql;
Create Table A As
Select Distinct
A.'ID'n,
B.'ITA ID'n,
B.'Open Date'n,
B.'Due Date'n,
B.'Status'n,
B.'Completion Date'n
From FolderName.ID as A
inner join FolderName.ITA as B
on A.'ID'n = B.'ID'n
Order by 'ID'n
;
Quit&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Sep 2022 17:57:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836179#M36030</guid>
      <dc:creator>squeakums</dc:creator>
      <dc:date>2022-09-30T17:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a statement to pull max date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836193#M36034</link>
      <description>If you want to keep all of the observations that are in the table ID. then use LEFT JOIN&lt;BR /&gt;&lt;BR /&gt;As to your other question, you could try to add this to your select statement (enclosed in commas)&lt;BR /&gt;max(B.'Open Date'n) as Max_date</description>
      <pubDate>Fri, 30 Sep 2022 18:55:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836193#M36034</guid>
      <dc:creator>svh</dc:creator>
      <dc:date>2022-09-30T18:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a statement to pull max date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836198#M36036</link>
      <description>&lt;P&gt;How would I write that in my code exactly?&amp;nbsp; This is not working unfortunately:&lt;/P&gt;&lt;PRE&gt;Proc Sql;
Create Table A As
Select Distinct
A.'ID'n,
B.'ITA ID'n,
B. max('Approval Date'n) as 'LatestApprovalDate'n,
B.'Due Date'n,
B.'Status'n,
B.'Completion Date'n
From FolderName.ID as A
inner join FolderName.ITA as B
on A.'ID'n = B.'ID'n
Order by 'ID'n
;
Quit&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Sep 2022 19:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836198#M36036</guid>
      <dc:creator>squeakums</dc:creator>
      <dc:date>2022-09-30T19:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a statement to pull max date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836201#M36037</link>
      <description>I think the B. is in the wrong place. Try this:&lt;BR /&gt;&lt;BR /&gt;max(B.'Approval_Date'n) as max_date&lt;BR /&gt;</description>
      <pubDate>Fri, 30 Sep 2022 19:36:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836201#M36037</guid>
      <dc:creator>svh</dc:creator>
      <dc:date>2022-09-30T19:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a statement to pull max date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836206#M36038</link>
      <description>&lt;P&gt;Okay, I updated this and it ran but it isn't pulling in dates - instead its pulling in 22914 for each row. Also, it still have dups for the ID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;ITA&lt;/TD&gt;&lt;TD&gt;LatestApprovalDate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;22914&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;ITA-125&lt;/TD&gt;&lt;TD&gt;22914&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;ITA-127&lt;/TD&gt;&lt;TD&gt;22914&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;ITA-187&lt;/TD&gt;&lt;TD&gt;22914&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;ITA-90&lt;/TD&gt;&lt;TD&gt;22914&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;15434&lt;/TD&gt;&lt;TD&gt;ITA-234&lt;/TD&gt;&lt;TD&gt;22914&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 30 Sep 2022 19:45:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836206#M36038</guid>
      <dc:creator>squeakums</dc:creator>
      <dc:date>2022-09-30T19:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a statement to pull max date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836233#M36042</link>
      <description>&lt;P&gt;This is the correct value, but it is not yet formatted to become human-readable.&lt;/P&gt;
&lt;P&gt;Add a FORMAT= option with a proper date format to the column definition.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 22:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836233#M36042</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-30T22:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a statement to pull max date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836261#M36047</link>
      <description>&lt;P&gt;The number&amp;nbsp;22,914 is the value SAS uses for the 26th of September of 2022.&lt;/P&gt;
&lt;P&gt;If you want SAS to print it in a more human friendly way then attach a numeric format that is designed to print date values to the new calculated variable.&amp;nbsp; Like DATE9. or YYMMDD10.&lt;/P&gt;
&lt;PRE&gt;5    data _null_;
6      date=22914;
7      put date= date9.;
8    run;

date=26SEP2022
&lt;/PRE&gt;
&lt;P&gt;You have multiple observations per ID because you selected extra variables (variables that are neither a grouping variable nor the result of an aggregate function).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't want the extra observations do not include the extra variables in the column list part of the SELECT statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table WANT as
select
  A.ID
, max(B.'Approval Date'n) as LatestApprovalDate format=date9.
from HAVE1 A
inner join HAVE2 B
on A.ID = B.ID
group by A.ID
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS It will be much easier to read and write your code if you set the VALIDVARNAME option to V7 instead of ANY.&amp;nbsp; That way SAS will prevent you from making variable names, like your examples with the spaces in them, that require the use of the cumbersome name literals in the code.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Oct 2022 06:36:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-a-statement-to-pull-max-date/m-p/836261#M36047</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-01T06:36:08Z</dc:date>
    </item>
  </channel>
</rss>

