<?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: Find the difference between two char type date variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-the-difference-between-two-char-type-date-variables/m-p/879173#M347344</link>
    <description>&lt;P&gt;Thank you for the reply. As I was trying it continuously, at last I got the solution to first convert the char type date variables to numeric using input for example:&lt;/P&gt;
&lt;P&gt;dt1_num = input(dt1,yymmdd10.) and then using format dt1_num yymmdd10.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly, converted the other date column dt2 also to numeric. I am converting to numeric only if the column is not equal to ' ' and it's length is 10.&lt;/P&gt;
&lt;P&gt;After this, I am able to calculate as per the formula I have mentioned in my previous post using these numeric columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 03 Jun 2023 18:29:43 GMT</pubDate>
    <dc:creator>Moksha</dc:creator>
    <dc:date>2023-06-03T18:29:43Z</dc:date>
    <item>
      <title>Find the difference between two char type date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-difference-between-two-char-type-date-variables/m-p/879170#M347342</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; In a dataset, I have two columns st_dt and end_dt which are char type dates :&lt;/P&gt;
&lt;PRE&gt;data have;
input dt1 $ 1-10 @12 dt2 $12.;
format dt1 $12. dt2 $12.;
datalines;
2012-02-22 2012-06-22
2012-02
2013-05-24
2013 2014-01-01
2013-01-01
;
run;

&lt;/PRE&gt;
&lt;P&gt;I have to calculate something like this:&lt;/P&gt;
&lt;P&gt;if&amp;nbsp; dt1 &amp;gt;= dt2 then var1 = (dt1-dt2) + 1;&lt;/P&gt;
&lt;P&gt;else var1 = dt2 -dt1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please, advise me how to do this with sample code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2023 17:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-difference-between-two-char-type-date-variables/m-p/879170#M347342</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-06-03T17:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Find the difference between two char type date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-difference-between-two-char-type-date-variables/m-p/879172#M347343</link>
      <description>&lt;P&gt;I guess you are using character variables because always know the year, but sometimes you don't know the day-of-month,&amp;nbsp; or the month and day-of-month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But to do the task you want, you first need to establish rules of assigning exact dates, in the face of those missing components.&amp;nbsp; So what are those rules?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you've got those rules, then you can establish numeric date values from your character dates.&amp;nbsp; Then it's trivial to do comparisons, differences, progression and regression through time span.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2023 18:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-difference-between-two-char-type-date-variables/m-p/879172#M347343</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-06-03T18:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: Find the difference between two char type date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-difference-between-two-char-type-date-variables/m-p/879173#M347344</link>
      <description>&lt;P&gt;Thank you for the reply. As I was trying it continuously, at last I got the solution to first convert the char type date variables to numeric using input for example:&lt;/P&gt;
&lt;P&gt;dt1_num = input(dt1,yymmdd10.) and then using format dt1_num yymmdd10.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly, converted the other date column dt2 also to numeric. I am converting to numeric only if the column is not equal to ' ' and it's length is 10.&lt;/P&gt;
&lt;P&gt;After this, I am able to calculate as per the formula I have mentioned in my previous post using these numeric columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2023 18:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-difference-between-two-char-type-date-variables/m-p/879173#M347344</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-06-03T18:29:43Z</dc:date>
    </item>
  </channel>
</rss>

