<?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: correction of a wrong date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/correction-of-a-wrong-date/m-p/677388#M204322</link>
    <description>Thank you for your reply&lt;BR /&gt;</description>
    <pubDate>Tue, 18 Aug 2020 05:21:05 GMT</pubDate>
    <dc:creator>PrasadYadla</dc:creator>
    <dc:date>2020-08-18T05:21:05Z</dc:date>
    <item>
      <title>correction of a wrong date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/correction-of-a-wrong-date/m-p/52890#M11191</link>
      <description>Is there any convenient way to correct a wrong date entered by users? For example, if a user enters "31apr2011"d, it will be corrected to "30apr2011"d by the program.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
a="31apr2011"d; /* a_corrected="30apr2011"d */&lt;BR /&gt;
b="30feb2011"d; /* b_corrected="28feb2011"d */&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 18 Apr 2011 22:06:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/correction-of-a-wrong-date/m-p/52890#M11191</guid>
      <dc:creator>MarcTC</dc:creator>
      <dc:date>2011-04-18T22:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: correction of a wrong date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/correction-of-a-wrong-date/m-p/52891#M11192</link>
      <description>Using a DATA step, you would need to use the INPUT function to test the data -- SAS will return a MISSING value if invalid, then set a DO/END loop decrementing by one and again testing the value using INPUT.  &lt;BR /&gt;
&lt;BR /&gt;
For consideration, the INPUT example below shows how to tell SAS to suppress an invalid-data condition from the SASLOG:&lt;BR /&gt;
&lt;BR /&gt;
test_date = INPUT(&lt;YOUR_CHAR_VARIABLE&gt;,?? DATE9.);&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/YOUR_CHAR_VARIABLE&gt;</description>
      <pubDate>Mon, 18 Apr 2011 22:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/correction-of-a-wrong-date/m-p/52891#M11192</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-04-18T22:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: correction of a wrong date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/correction-of-a-wrong-date/m-p/52892#M11193</link>
      <description>If, as your sample suggests, you are only worried about the last day of the month, the following uses Scott's suggestion to create a new date value.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data a;&lt;BR /&gt;
a="31apr2011"; output;&lt;BR /&gt;
a="30feb2011"; output;&lt;BR /&gt;
a="15sep2011"; output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data last;&lt;BR /&gt;
set a;&lt;BR /&gt;
date = INPUT(a,?? DATE9.);&lt;BR /&gt;
if date= . then do;&lt;BR /&gt;
   substr(a,1,2)='01';&lt;BR /&gt;
   date=intnx('month',input(a,date9.),0,'e');&lt;BR /&gt;
end;&lt;BR /&gt;
format date date9.;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data=last;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Clearly there are other date traps that may concern you.</description>
      <pubDate>Wed, 20 Apr 2011 03:39:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/correction-of-a-wrong-date/m-p/52892#M11193</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2011-04-20T03:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: correction of a wrong date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/correction-of-a-wrong-date/m-p/677132#M204235</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What if the date column has missing values from before and few dates have the wrong day (31&amp;amp; 32) .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 04:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/correction-of-a-wrong-date/m-p/677132#M204235</guid>
      <dc:creator>PrasadYadla</dc:creator>
      <dc:date>2020-08-17T04:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: correction of a wrong date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/correction-of-a-wrong-date/m-p/677134#M204236</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/341910"&gt;@PrasadYadla&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What if the date column has missing values from before and few dates have the wrong day (31&amp;amp; 32) .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Enclosing the correcting code with an appropriate if-statement should help:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
   a="31apr2011";
   output;
   a="30feb2011";
   output;
   a = " ";
   output;
   a="15sep2011";
   output;
run;

data last;
   set a;

   if not missing(a) then
      do;
         date=INPUT(a, ?? DATE9.);

         if date=. then
            do;
               substr(a, 1, 2)='01';
               date=intnx('month', input(a, date9.), 0, 'e');
            end;
      end;
   format date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Aug 2020 05:04:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/correction-of-a-wrong-date/m-p/677134#M204236</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-17T05:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: correction of a wrong date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/correction-of-a-wrong-date/m-p/677388#M204322</link>
      <description>Thank you for your reply&lt;BR /&gt;</description>
      <pubDate>Tue, 18 Aug 2020 05:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/correction-of-a-wrong-date/m-p/677388#M204322</guid>
      <dc:creator>PrasadYadla</dc:creator>
      <dc:date>2020-08-18T05:21:05Z</dc:date>
    </item>
  </channel>
</rss>

