<?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 compare date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489807#M127970</link>
    <description>&lt;P&gt;please try the below code&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if there is only year like 2011 then I imputed it to 01-01, let me know if that works for the other imputation suggested is followed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id date1 $10. date2 $11. ;
  if length(date1)&amp;lt;10 then cd1=intnx('month',input(cats(date1,'-01'),yymmdd10.),0,'e');
 else if length(date1)&amp;gt;=10 then cd1=input(date1,anydtdte10.);

     if length(date2)&amp;lt;=4 then cd2=intnx('year',input(cats(date2,'-01-01'),yymmdd10.),0,'s');
	else if 4&amp;lt; length(date2)&amp;lt;10 then cd2=intnx('month',input(cats(date2,'-01'),yymmdd10.),0,'e');
   else if length(date2)&amp;gt;=10 then cd2=input(date2,anydtdte10.);
   if cd2&amp;lt;cd1 then want='early';
   else want='late';
  format cd: date9.;
datalines;
1 05/21/2010 2013-03-21
2 2011-03-01 2011-01-21
3 2014-03    2011
4 2015-01    2015-05
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 25 Aug 2018 05:24:31 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2018-08-25T05:24:31Z</dc:date>
    <item>
      <title>how to compare date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489785#M127959</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to&amp;nbsp;compare different date. I have two questions here.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. how to compare those date and conclude as shown in 'want'?&lt;/P&gt;&lt;P&gt;2. the original data is&amp;nbsp;same as shown in 'dataline'. How could I input the date2 as numeric?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dataline
id date1 $ date2  ;

1 05/21/2010 2013-03-21
2 2011-03-01 2011-01-21
3 2014-03    2011
4 2015-01    2015-05
;
run;

want
1 late
2 early
3 early
4 late&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Aug 2018 22:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489785#M127959</guid>
      <dc:creator>xiangpang</dc:creator>
      <dc:date>2018-08-24T22:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489791#M127961</link>
      <description>&lt;P&gt;The ANYDTDTE informat can read a lot of different date strings. But it doesn't handle a bare 4 digit year. So add a little more logic to handle those cases.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id date1 date2 @1 id cdate1 :$10. cdate2 :$10.;
  informat date1 date2 anydtdte. ;
  format date1 date2 yymmdd10. ;
  if length(cdate1)=4 then date1=mdy(1,1,input(cdate1,4.));
  if length(cdate2)=4 then date2=mdy(1,1,input(cdate2,4.));
  if date2 &amp;lt; date1 then want='early';
  else want='late';
datalines;
1 05/21/2010 2013-03-21
2 2011-03-01 2011-01-21
3 2014-03    2011
4 2015-01    2015-05
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    id         date1         date2      cdate1      cdate2        want

 1      1    2010-05-21    2013-03-21    05/21/2010    2013-03-21    late
 2      2    2011-03-01    2011-01-21    2011-03-01    2011-01-21    early
 3      3    2014-03-01    2011-01-01    2014-03       2011          early
 4      4    2015-01-01    2015-05-01    2015-01       2015-05       late&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Aug 2018 00:38:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489791#M127961</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-25T00:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489792#M127962</link>
      <description>&lt;P&gt;thanks for reply. if one cdate1 is&amp;nbsp;2014-03 and another cdate1 is&amp;nbsp;2014-04, could I convert them to date1 as 2014-03-31 and date1 as 2014-4-30 instead of 01-01?&lt;/P&gt;</description>
      <pubDate>Sat, 25 Aug 2018 01:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489792#M127962</guid>
      <dc:creator>xiangpang</dc:creator>
      <dc:date>2018-08-25T01:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489805#M127969</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194581"&gt;@xiangpang&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;thanks for reply. if one cdate1 is&amp;nbsp;2014-03 and another cdate1 is&amp;nbsp;2014-04, could I convert them to date1 as 2014-03-31 and date1 as 2014-4-30 instead of 01-01?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Add the statements&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if length(cdate1)=7 then date1 = intnx("month", date1, 0, "END"); 
if length(cdate2)=7 then date2 = intnx("month", date2, 0, "END"); &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Aug 2018 05:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489805#M127969</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-08-25T05:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489807#M127970</link>
      <description>&lt;P&gt;please try the below code&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if there is only year like 2011 then I imputed it to 01-01, let me know if that works for the other imputation suggested is followed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id date1 $10. date2 $11. ;
  if length(date1)&amp;lt;10 then cd1=intnx('month',input(cats(date1,'-01'),yymmdd10.),0,'e');
 else if length(date1)&amp;gt;=10 then cd1=input(date1,anydtdte10.);

     if length(date2)&amp;lt;=4 then cd2=intnx('year',input(cats(date2,'-01-01'),yymmdd10.),0,'s');
	else if 4&amp;lt; length(date2)&amp;lt;10 then cd2=intnx('month',input(cats(date2,'-01'),yymmdd10.),0,'e');
   else if length(date2)&amp;gt;=10 then cd2=input(date2,anydtdte10.);
   if cd2&amp;lt;cd1 then want='early';
   else want='late';
  format cd: date9.;
datalines;
1 05/21/2010 2013-03-21
2 2011-03-01 2011-01-21
3 2014-03    2011
4 2015-01    2015-05
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Aug 2018 05:24:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489807#M127970</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-08-25T05:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489815#M127972</link>
      <description>&lt;P&gt;Thanks a lot. it is what I want.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Aug 2018 12:20:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489815#M127972</guid>
      <dc:creator>xiangpang</dc:creator>
      <dc:date>2018-08-25T12:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to compare date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489818#M127974</link>
      <description>&lt;P&gt;Thanks a lot. I learned intnx function from you guys. I did not know that before.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a good day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Aug 2018 12:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-compare-date/m-p/489818#M127974</guid>
      <dc:creator>xiangpang</dc:creator>
      <dc:date>2018-08-25T12:27:02Z</dc:date>
    </item>
  </channel>
</rss>

