<?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: Need help with dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/316233#M69075</link>
    <description>&lt;P&gt;Yep - Having the same problems. My manager insists we use ISO8601 format, but SAS has no inclination to honour ISO standards.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We put postfix on datasets as _yyyymmdd and declare such dates as Macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only when you try to read such a date into a dataset with a Where clause we get terrible problems:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let dtToday = %sysfunc(date(),yymmddn8.);

Testfile is specified as 
Data TestFile;
Length FileName $30.;
/*===We use a Tab as a delimiter===*/
Infile Datalines dlm='09'x;
Input LoadDate Date9. FileName $ VerNo 2.;
FORMAT LoadDate Date9. FileName $30.;
Datalines;
30NOV2016 20161130_1.zip 1
01DEC2016 20161201_2.zip 2
02DEC2016 20161202_3.zip 3
05DEC2016 20161205_4.zip 4
06DEC2016 20161206_5.zip 5
;
Run;

Data test;&lt;BR /&gt;SET TestFile;&lt;BR /&gt;where LoadDate = inputn(&amp;amp;dtToday,yymmddn8.);&lt;BR /&gt;/*where LoadDate = inputn(&amp;amp;dtToday,Date9.);&lt;BR /&gt;where LoadDate = inputn(&amp;amp;dtToday,yymmdd10.);&lt;BR /&gt;where LoadDate = "&amp;amp;dtToday"d;*/&lt;BR /&gt;/*where LoadDate = &amp;amp;dtToday;*/&lt;BR /&gt;run;

31         where LoadDate = inputn(&amp;amp;dtToday,yymmdd10.);
                                            _________
                                            201
ERROR 201-322: The option is not recognized and will be ignored.

ERROR: Syntax error while parsing WHERE clause.
&lt;/PRE&gt;
&lt;P&gt;This should not be so hard - why is this proving to be so extremely difficult??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Dec 2016 12:38:28 GMT</pubDate>
    <dc:creator>Lenvdb</dc:creator>
    <dc:date>2016-12-02T12:38:28Z</dc:date>
    <item>
      <title>Need help with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92675#M19521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Greetings.&amp;nbsp; In a dataset I have a date variable that is (or should be) a date.&amp;nbsp; It is in format 'YYYY-MM-DD', and when I look at the dataset properties for that column, the format is YYMMDD10. and the Informat is YYMMDD10.&amp;nbsp; So, in my code, I want to put some conditions on the date...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If Date_variable &amp;gt;= '2013-07-26'd&amp;nbsp; Then...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I keep getting error: ERROR: Invalid date/time/datetime constant '2013-07-26'd.&amp;nbsp; I have tried '2013-07-26'd, '20130726'd, '26JUL2013'd, '07/26/2013'd, and everything else I could think of, and I am still getting errors.&amp;nbsp; I'm sure it something simple (and very frustrating), but I can't make it work.&amp;nbsp; Can anyone help?&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jul 2013 19:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92675#M19521</guid>
      <dc:creator>gsnidow</dc:creator>
      <dc:date>2013-07-26T19:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92676#M19522</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;try:&lt;/P&gt;&lt;P&gt;If Date_variable &amp;gt;= mdy(07,26,2013);&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;If Date_variable &amp;gt;= '26jul2013'd; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jul 2013 19:29:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92676#M19522</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2013-07-26T19:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92677#M19523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Use of '26JUL2013'd for your example should have worked. Please try with this value and then if the error persists copy the code and entire error message from the log and post here.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jul 2013 19:30:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92677#M19523</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-07-26T19:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92678#M19524</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if &lt;SPAN style="color: #ff0000;"&gt;Date_variable&lt;/SPAN&gt; is a character variable, then try:&lt;/P&gt;&lt;P&gt;input(date_variable,yymmdd10.)&amp;gt;mdy(7,26,2013);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Jul 2013 19:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92678#M19524</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2013-07-26T19:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92679#M19525</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since both the format and the informat are yymmdd10. for the date, make sure that the date_variables are also in the same format and informat,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then you can use the following code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if date_variable&amp;gt;=input('2013-07-26',yymmdd10.) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jagadish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Jul 2013 05:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92679#M19525</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2013-07-27T05:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92680#M19526</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why would you ever have&lt;/P&gt;&lt;P&gt; a)&amp;nbsp; "if date_variable&amp;gt;=input('2013-07-26',yymmdd10.);"&lt;/P&gt;&lt;P&gt;instead of&lt;/P&gt;&lt;P&gt; b) "if date_variable&amp;gt;='26jul2013'd;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Both versions assume that date_variable is (1) numeric, and (2) contains a date value.&amp;nbsp; It matters not what format or informat has been assigned to the variable.&amp;nbsp; And version (a) will ask SAS to needlessly run the INPUT function NOBS time, always getting the same result, namely '26jul2013'd for comparison purposes.&amp;nbsp; Version b has no such overhead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Jul 2013 02:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92680#M19526</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2013-07-28T02:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92681#M19527</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The main reason for suggesting the use of the code "&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if date_variable&amp;gt;=input('2013-07-26',yymmdd10.) ;&lt;/SPAN&gt;", as per the query the date when used this way &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;'2013-07-26'd is not recognized by the system and is producing the errors as below &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR: Invalid date/time/datetime constant '2013-07-26'd.&lt;/P&gt;&lt;P&gt;ERROR 77-185: Invalid number conversion on '2013-07-26'd.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The system is unable to recognize the date given in the format '2013-07-26'd, so it is essential that we read the date using the input function and then pass the condition. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;This code "if date_variable&amp;gt;='26jul2013'd;" will work well. However i have given an alternative way to this.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Both the way will definitely work. &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i am open to any further suggestions. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jagadish &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Jul 2013 03:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92681#M19527</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2013-07-28T03:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92682#M19528</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Date literals in SAS only work with DATE. format.&amp;nbsp; So you can use '26JUL2013'd but you cannot use '2013-07-26'd.&lt;/P&gt;&lt;P&gt;So it is probably easiest to just change your code to specify date literals in the form that SAS wants.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now if the source of the data for the dates is not just the program code and it is only available in yymmdd format you can convert it using the INPUT() or INPUTN() function.&amp;nbsp; If you have it as a macro variable then you can use %sysfunc() to call the INPUTN() function to convert to either the internal date value (days since 1/1/1960) or DATE9 format that you CAN use as a date literal..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let keydate=2013-07-26;&lt;/P&gt;&lt;P&gt;%let keydate=%sysfunc(inputn(&amp;amp;keydate,yymmdd10.),date9.);&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;If Date_variable &amp;gt;= "&amp;amp;keydate"d&amp;nbsp; Then...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Jul 2013 04:06:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92682#M19528</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-07-28T04:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92683#M19529</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes Tom, the sas is unable to recognize date in 'yymmdd'd literals, so the best way would be to read the date with the informat yymmdd10. and use the date9. format as rightly mentioned by you. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Jul 2013 04:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92683#M19529</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2013-07-28T04:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92684#M19530</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all so much for the help.&amp;nbsp; Dates in SAS are proving troublesome to get.&amp;nbsp; The data is coming from an ODBC connection to DB2, where all dates are in yyyy-mm-dd format (according to Wiki, it is ISO 8601 format).&amp;nbsp; Anyhow, I think the best thing to do is to format them so I can use literals.&amp;nbsp; For some reason our IE at work will not allow most of the buttons to work on the forum, so I was able to add a topic, but then I could not navigate back to it when I came back to work the next week.&amp;nbsp; Thanks again everyone.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Aug 2013 00:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/92684#M19530</guid>
      <dc:creator>gsnidow</dc:creator>
      <dc:date>2013-08-07T00:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/316233#M69075</link>
      <description>&lt;P&gt;Yep - Having the same problems. My manager insists we use ISO8601 format, but SAS has no inclination to honour ISO standards.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We put postfix on datasets as _yyyymmdd and declare such dates as Macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only when you try to read such a date into a dataset with a Where clause we get terrible problems:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let dtToday = %sysfunc(date(),yymmddn8.);

Testfile is specified as 
Data TestFile;
Length FileName $30.;
/*===We use a Tab as a delimiter===*/
Infile Datalines dlm='09'x;
Input LoadDate Date9. FileName $ VerNo 2.;
FORMAT LoadDate Date9. FileName $30.;
Datalines;
30NOV2016 20161130_1.zip 1
01DEC2016 20161201_2.zip 2
02DEC2016 20161202_3.zip 3
05DEC2016 20161205_4.zip 4
06DEC2016 20161206_5.zip 5
;
Run;

Data test;&lt;BR /&gt;SET TestFile;&lt;BR /&gt;where LoadDate = inputn(&amp;amp;dtToday,yymmddn8.);&lt;BR /&gt;/*where LoadDate = inputn(&amp;amp;dtToday,Date9.);&lt;BR /&gt;where LoadDate = inputn(&amp;amp;dtToday,yymmdd10.);&lt;BR /&gt;where LoadDate = "&amp;amp;dtToday"d;*/&lt;BR /&gt;/*where LoadDate = &amp;amp;dtToday;*/&lt;BR /&gt;run;

31         where LoadDate = inputn(&amp;amp;dtToday,yymmdd10.);
                                            _________
                                            201
ERROR 201-322: The option is not recognized and will be ignored.

ERROR: Syntax error while parsing WHERE clause.
&lt;/PRE&gt;
&lt;P&gt;This should not be so hard - why is this proving to be so extremely difficult??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2016 12:38:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dates/m-p/316233#M69075</guid>
      <dc:creator>Lenvdb</dc:creator>
      <dc:date>2016-12-02T12:38:28Z</dc:date>
    </item>
  </channel>
</rss>

