<?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: Can not get a distinct list with date/time field. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627217#M20506</link>
    <description>&lt;P&gt;Hello Again and thank you so much for the quick responses!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;I updated the query twice and re-run (1st with Group by ID1 and 2nd without Group by) It ran successfully but still not the correct results ... also the log says, "NOTE: The query requires remerging summary statistics back with the original data." What does this mean, please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the result but again it should only return with the 1st row:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID1&lt;/TD&gt;&lt;TD&gt;ID2&lt;/TD&gt;&lt;TD&gt;CYCLE_DATE&lt;/TD&gt;&lt;TD&gt;AMOUNT&lt;/TD&gt;&lt;TD&gt;STATUS&lt;/TD&gt;&lt;TD&gt;MAX_of_DTTM_CREATE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;987654321&lt;/TD&gt;&lt;TD&gt;31-Dec-19&lt;/TD&gt;&lt;TD&gt;1.67&lt;/TD&gt;&lt;TD&gt;Active&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;03JAN2020:03:04:35.353335&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;987654321&lt;/TD&gt;&lt;TD&gt;31-Dec-19&lt;/TD&gt;&lt;TD&gt;2.01&lt;/TD&gt;&lt;TD&gt;Active&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;03JAN2020:03:04:35.353335&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;I need the latest and greatest dttm_create per record per cycle date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;My apologies on the group by clause, I'm not really sure what I'm doing &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Feb 2020 15:49:13 GMT</pubDate>
    <dc:creator>Mary001</dc:creator>
    <dc:date>2020-02-25T15:49:13Z</dc:date>
    <item>
      <title>Can not get a distinct list with date/time field.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627203#M20498</link>
      <description>&lt;P&gt;Hi There,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to SAS, using SAS Enterprise Guide 7.12 and running this code. I can't seem to get a distinct list based on the dttm_create. I tried using group by and having, sub-query and all other different variations but nothing seem to work. The SQL runs fine (no sql error) but just not returning the correct results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help? I've been at this for 2 days now &lt;img id="smileysad" class="emoticon emoticon-smileysad" src="https://communities.sas.com/i/smilies/16x16_smiley-sad.png" alt="Smiley Sad" title="Smiley Sad" /&gt; Thank you so much in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.TABLE2 AS&lt;BR /&gt;SELECT DISTINCT ID1, ID2, CYCLE_DATE, AMT, STATUS,&lt;BR /&gt;MAX(DTTM_CREATE) FORMAT=DATETIME25.6 AS MAX_of_DTTM_CREATE&lt;BR /&gt;FROM WORK.TABLE1&lt;BR /&gt;WHERE ID1 = '123456789'&lt;BR /&gt;GROUP BY ID1,&lt;BR /&gt;ID2, CYCLE_DATE,&lt;BR /&gt;AMT, STATUS, DTTM_CREATE;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the result I'm getting but the SQL should only give me the first row.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID1&lt;/TD&gt;&lt;TD&gt;ID2&lt;/TD&gt;&lt;TD&gt;CYCLE_DATE&lt;/TD&gt;&lt;TD&gt;AMOUNT&lt;/TD&gt;&lt;TD&gt;STATUS&lt;/TD&gt;&lt;TD&gt;MAX_of_DTTM_CREATE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;123456789&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;987654321&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;31-Dec-19&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;1.67&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Active&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;03JAN2020:03:04:35.353335&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;987654321&lt;/TD&gt;&lt;TD&gt;31-Dec-19&lt;/TD&gt;&lt;TD&gt;2.01&lt;/TD&gt;&lt;TD&gt;Active&lt;/TD&gt;&lt;TD&gt;06DEC2019:02:48:35.810525&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 25 Feb 2020 15:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627203#M20498</guid>
      <dc:creator>Mary001</dc:creator>
      <dc:date>2020-02-25T15:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Can not get a distinct list with date/time field.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627204#M20499</link>
      <description>&lt;P&gt;Why are you including all of those extra variables in the GROUP BY?&amp;nbsp; Which variables do you actually want to use to define the group that you want to use to find max of&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;DTTM_CREATE in the group ?&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here is simpler query you might try to see the difference that changing the GROUP BY makes.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This is like your query:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select sex,max(age) as max_age
from sashelp.class
group by sex, age
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;This is more appropriate:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select sex,max(age) as max_age
from sashelp.class
group by sex
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Feb 2020 15:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627204#M20499</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-25T15:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Can not get a distinct list with date/time field.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627205#M20500</link>
      <description>&lt;P&gt;Distinct works only on the entire collection of variables in the CREATE TABLE. It doesn't work if you want one or two variables to be distinct and not the other.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the criteria that lets you determine that you want the first record here and not the other records?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 15:26:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627205#M20500</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-25T15:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Can not get a distinct list with date/time field.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627206#M20501</link>
      <description>&lt;P&gt;HI &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/313784"&gt;@Mary001&lt;/a&gt;&amp;nbsp; First off&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Are you sure&amp;nbsp;&lt;SPAN&gt;DTTM_CREATE should be part of GROUP BY Clause&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2. Are you sure AMT should be part of GROUP BY clause&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the above questions make sense, it appears the SQL you are prolly after is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WORK.TABLE2 AS
SELECT DISTINCT ID1, ID2, CYCLE_DATE, AMT, STATUS,
MAX(DTTM_CREATE) FORMAT=DATETIME25.6 AS MAX_of_DTTM_CREATE
FROM WORK.TABLE1
WHERE ID1 = '123456789'
GROUP BY ID1,ID2, CYCLE_DATE, STATUS
having MAX_of_DTTM_CREATE=DTTM_CREATE;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Or with the corrected GROUP BY clauses knowing there isn't any column that is specified in the SELECT Clause not part of the Group by that may cause potential remerging*/&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WORK.TABLE2 AS
SELECT DISTINCT ID1, ID2, CYCLE_DATE, AMT, STATUS,
MAX(DTTM_CREATE) FORMAT=DATETIME25.6 AS MAX_of_DTTM_CREATE
FROM WORK.TABLE1
WHERE ID1 = '123456789'
GROUP BY ID1,ID2, CYCLE_DATE, STATUS;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above assumes there are no ties in MAX of&amp;nbsp;&lt;SPAN&gt;DTTM_CREATE and secondly status is either ACTIVE or NOT forming a group. Please let us know. Thank you&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 15:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627206#M20501</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-25T15:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can not get a distinct list with date/time field.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627217#M20506</link>
      <description>&lt;P&gt;Hello Again and thank you so much for the quick responses!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;I updated the query twice and re-run (1st with Group by ID1 and 2nd without Group by) It ran successfully but still not the correct results ... also the log says, "NOTE: The query requires remerging summary statistics back with the original data." What does this mean, please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the result but again it should only return with the 1st row:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID1&lt;/TD&gt;&lt;TD&gt;ID2&lt;/TD&gt;&lt;TD&gt;CYCLE_DATE&lt;/TD&gt;&lt;TD&gt;AMOUNT&lt;/TD&gt;&lt;TD&gt;STATUS&lt;/TD&gt;&lt;TD&gt;MAX_of_DTTM_CREATE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;987654321&lt;/TD&gt;&lt;TD&gt;31-Dec-19&lt;/TD&gt;&lt;TD&gt;1.67&lt;/TD&gt;&lt;TD&gt;Active&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;03JAN2020:03:04:35.353335&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;987654321&lt;/TD&gt;&lt;TD&gt;31-Dec-19&lt;/TD&gt;&lt;TD&gt;2.01&lt;/TD&gt;&lt;TD&gt;Active&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;03JAN2020:03:04:35.353335&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;I need the latest and greatest dttm_create per record per cycle date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;My apologies on the group by clause, I'm not really sure what I'm doing &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 15:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627217#M20506</guid>
      <dc:creator>Mary001</dc:creator>
      <dc:date>2020-02-25T15:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: Can not get a distinct list with date/time field.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627218#M20507</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/313784"&gt;@Mary001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;I need the latest and greatest dttm_create per record per cycle date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WORK.TABLE2 AS
SELECT ID1, ID2, CYCLE_DATE, AMT, STATUS,
DTTM_CREATE FORMAT=DATETIME25.6
FROM WORK.TABLE1
WHERE ID1 = '123456789'
GROUP BY ID1,ID2, CYCLE_DATE
having dttm_create=max(dttm_create);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Feb 2020 15:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627218#M20507</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-25T15:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Can not get a distinct list with date/time field.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627225#M20509</link>
      <description>&lt;P&gt;THANK YOU so much everyone!!! You guys are amazing!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I re-ran with the updated sql from Paige and received the correct results &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 16:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-not-get-a-distinct-list-with-date-time-field/m-p/627225#M20509</guid>
      <dc:creator>Mary001</dc:creator>
      <dc:date>2020-02-25T16:09:33Z</dc:date>
    </item>
  </channel>
</rss>

