<?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: All dates 'later than'.... returns wrong results in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/All-dates-later-than-returns-wrong-results/m-p/26237#M5983</link>
    <description>Review your SAS Log output closely, with your second DATA step; there should be a message ONE_DATE_END VARIABLE IS UNINITIALIZED.  &lt;BR /&gt;
&lt;BR /&gt;
Check your INPUT function to assign FINAL, and you will find that the INFORMAT being used is incorrect -- there should be a SAS diagnostic related.&lt;BR /&gt;
&lt;BR /&gt;
So, for your own desk-checking diagnostics and validation consider using SAS FORMAT statements for variables like FINAL, to represent them as a DATE string.  Then use PROC PRINT along the way (after the DATA steps), or use SAS PUTLOG commands in the DATA step to see what is being derived for your assignment statement.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Fri, 01 May 2009 18:55:58 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-05-01T18:55:58Z</dc:date>
    <item>
      <title>All dates 'later than'.... returns wrong results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/All-dates-later-than-returns-wrong-results/m-p/26234#M5980</link>
      <description>I have a field called end_date with a variable type 'datetime'. example of record is   31MAR2009:00:00:08&lt;BR /&gt;
&lt;BR /&gt;
I used the following command to get the date part&lt;BR /&gt;
sas_end_date=put(datepart(date_end),date9.);&lt;BR /&gt;
&lt;BR /&gt;
the sas_end_date has date in the format 20JAN2009 etc.&lt;BR /&gt;
&lt;BR /&gt;
Goal: To return only those records which have date later than 29 april 2009. But when I use the code below, it does not give me the required results.&lt;BR /&gt;
&lt;BR /&gt;
data test2;&lt;BR /&gt;
set test1;&lt;BR /&gt;
where sas_end_date gt '29APR2009';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
It deletes many records but the resulting data sets have dates from 2004 to 2009 December.&lt;BR /&gt;
&lt;BR /&gt;
When I use less than&lt;BR /&gt;
&lt;BR /&gt;
data test2;&lt;BR /&gt;
set test1;&lt;BR /&gt;
where sas_end_date lt '29APR2009';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
it does not delete a single record.&lt;BR /&gt;
&lt;BR /&gt;
Useful information: The sas_date_end variable is of type $9 standard character. Why is this the case, shouldn't it be date since I used datepart function above?</description>
      <pubDate>Fri, 01 May 2009 18:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/All-dates-later-than-returns-wrong-results/m-p/26234#M5980</guid>
      <dc:creator>osho</dc:creator>
      <dc:date>2009-05-01T18:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: All dates 'later than'.... returns wrong results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/All-dates-later-than-returns-wrong-results/m-p/26235#M5981</link>
      <description>SAS DATE and DATETIME type variables are numeric, not character, and so you must use the numeric-version for properly GT/LT testing, instead of using character-format representations.  Also, when you want to refer to a SAS date or datetime literal in single- or double-quotation marks, you just append the identifier "D" or "DT" to the literal string that is enclosed in the quotation.&lt;BR /&gt;
&lt;BR /&gt;
Recommended reading from the SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website on the topic of using SAS DATE and DATETIME variables:&lt;BR /&gt;
&lt;BR /&gt;
About SAS Date, Time, and Datetime Values&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002200738.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002200738.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Also, a SAS supplemental technical paper on this topic:&lt;BR /&gt;
&lt;BR /&gt;
SAS Dates, Times, and Interval Functions&lt;BR /&gt;
Definitions and Explanations&lt;BR /&gt;
SAS Dates, Times, and Datetimes:&lt;BR /&gt;
&lt;A href="http://support.sas.com/techsup/technote/ts668.pdf" target="_blank"&gt;http://support.sas.com/techsup/technote/ts668.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 01 May 2009 18:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/All-dates-later-than-returns-wrong-results/m-p/26235#M5981</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-01T18:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: All dates 'later than'.... returns wrong results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/All-dates-later-than-returns-wrong-results/m-p/26236#M5982</link>
      <description>Thanks for your reply. I had already read the links you sent and tried it.&lt;BR /&gt;
&lt;BR /&gt;
When I convert the field type to numeric, I used the code below&lt;BR /&gt;
&lt;BR /&gt;
data test1;	&lt;BR /&gt;
set test;&lt;BR /&gt;
onedate_end_date=put(datepart(date_end),date9.);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
which was fine.&lt;BR /&gt;
&lt;BR /&gt;
Then I try to find all records that have dates later than 29 April 2009&lt;BR /&gt;
&lt;BR /&gt;
data test1;&lt;BR /&gt;
set test1;&lt;BR /&gt;
final=input(onedate_end,9.); /*convert date field to numeric*/&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data test2;&lt;BR /&gt;
set test1;&lt;BR /&gt;
where final gt "29APR2009"d;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
It deleted all records!&lt;BR /&gt;
What am I missing here?&lt;BR /&gt;
Thanks in advance.</description>
      <pubDate>Fri, 01 May 2009 18:37:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/All-dates-later-than-returns-wrong-results/m-p/26236#M5982</guid>
      <dc:creator>osho</dc:creator>
      <dc:date>2009-05-01T18:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: All dates 'later than'.... returns wrong results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/All-dates-later-than-returns-wrong-results/m-p/26237#M5983</link>
      <description>Review your SAS Log output closely, with your second DATA step; there should be a message ONE_DATE_END VARIABLE IS UNINITIALIZED.  &lt;BR /&gt;
&lt;BR /&gt;
Check your INPUT function to assign FINAL, and you will find that the INFORMAT being used is incorrect -- there should be a SAS diagnostic related.&lt;BR /&gt;
&lt;BR /&gt;
So, for your own desk-checking diagnostics and validation consider using SAS FORMAT statements for variables like FINAL, to represent them as a DATE string.  Then use PROC PRINT along the way (after the DATA steps), or use SAS PUTLOG commands in the DATA step to see what is being derived for your assignment statement.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 01 May 2009 18:55:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/All-dates-later-than-returns-wrong-results/m-p/26237#M5983</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-01T18:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: All dates 'later than'.... returns wrong results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/All-dates-later-than-returns-wrong-results/m-p/26238#M5984</link>
      <description>The core problem is your put element.&lt;BR /&gt;
&lt;BR /&gt;
onedate_end_date=put(datepart(date_end),date9.);&lt;BR /&gt;
&lt;BR /&gt;
That creates a character string that looks like a date.&lt;BR /&gt;
&lt;BR /&gt;
To get a SAS date, use&lt;BR /&gt;
enddate=datepart(date_end);&lt;BR /&gt;
format enddate date9.;&lt;BR /&gt;
&lt;BR /&gt;
Then your where statement would look like&lt;BR /&gt;
&lt;BR /&gt;
where enddate gt '29APR2009'd;&lt;BR /&gt;
&lt;BR /&gt;
(note the "d" at the end of the date constant).&lt;BR /&gt;
&lt;BR /&gt;
Doc</description>
      <pubDate>Fri, 01 May 2009 19:32:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/All-dates-later-than-returns-wrong-results/m-p/26238#M5984</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2009-05-01T19:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: All dates 'later than'.... returns wrong results</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/All-dates-later-than-returns-wrong-results/m-p/26239#M5985</link>
      <description>Thank you Doc@Duke. I realized my folly and achieved my results.&lt;BR /&gt;
Many thanks for your time.</description>
      <pubDate>Mon, 04 May 2009 18:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/All-dates-later-than-returns-wrong-results/m-p/26239#M5985</guid>
      <dc:creator>osho</dc:creator>
      <dc:date>2009-05-04T18:39:29Z</dc:date>
    </item>
  </channel>
</rss>

