<?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: Date calculation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607827#M176770</link>
    <description>&lt;P&gt;Sorry formats wouldn't have any effect. What are the column attribute types for these 2 dates. Character or numeric?&lt;/P&gt;</description>
    <pubDate>Wed, 27 Nov 2019 19:48:00 GMT</pubDate>
    <dc:creator>Krueger</dc:creator>
    <dc:date>2019-11-27T19:48:00Z</dc:date>
    <item>
      <title>Date calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607816#M176763</link>
      <description>&lt;P&gt;Hi there&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I'm attempt to calculate the days between varible 'date' and 'edate',&amp;nbsp; I used following codes:&amp;nbsp;&lt;/P&gt;&lt;P&gt;data final3;&lt;BR /&gt;set final2;&lt;BR /&gt;dt = input(date, yymmdd10.);&lt;BR /&gt;edt = input(edate, yymmdd10.);&lt;BR /&gt;dd = dt - edt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works before, but for somereason, it not work anymore.&amp;nbsp;&lt;/P&gt;&lt;P&gt;the log information shows that&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 622:12&amp;nbsp;&amp;nbsp; 623:13&lt;/P&gt;&lt;P&gt;NOTE: Invalid argument to function INPUT at line 623 column 7.&lt;/P&gt;&lt;P&gt;Company_Name=ARCHER-DANIELS-MIDLAND CO TICKER=ADM EDATE=20140204 Date=20100107 Price=31.23 dt=22189 edt=. dd=.&lt;/P&gt;&lt;P&gt;_ERROR_=1 _N_=4&lt;/P&gt;&lt;P&gt;NOTE: Invalid argument to function INPUT at line 623 column 7.&lt;/P&gt;&lt;P&gt;Company_Name=ARCHER-DANIELS-MIDLAND CO TICKER=ADM EDATE=20150203 Date=20100108 Price=30.84 dt=22189 edt=. dd=.&lt;/P&gt;&lt;P&gt;_ERROR_=1 _N_=5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know why it not work in this case.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suspect that maybe the format of the "date" and "edate" has some problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 19:25:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607816#M176763</guid>
      <dc:creator>Xinhui</dc:creator>
      <dc:date>2019-11-27T19:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Date calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607817#M176764</link>
      <description>&lt;P&gt;Are you trying to get a date or a character result? INPUT() is converting both date and edate (assuming they were numeric to begin with) to character. If your trying to subtract a date from another date however they would need to be numeric. Try something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dd = date-edate;
format dd yymmdd10.;&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run a proc contents and look at what your formats are on date and edate. I'm guessing one might be character and you need to convert it to numeric first.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 19:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607817#M176764</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-11-27T19:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Date calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607822#M176766</link>
      <description>&lt;P&gt;&lt;SPAN&gt;data final3;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;set final2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FORMAT DATE MMDDYY10.;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FORMAT EDATE MMDDYY10.;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;DD=DATE- EDATE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Initially, I used this code, it not works, then someone suggested me to use &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data final3;&lt;BR /&gt;set final2;&lt;BR /&gt;dt = input(date, yymmdd10.);&lt;BR /&gt;edt = input(edate, yymmdd10.);&lt;BR /&gt;dd = dt - edt;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;it worked, but I rerun the whole project again, it not works again.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I though there are some format problems with "date""edate", now is best12 format.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 19:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607822#M176766</guid>
      <dc:creator>Xinhui</dc:creator>
      <dc:date>2019-11-27T19:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: Date calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607827#M176770</link>
      <description>&lt;P&gt;Sorry formats wouldn't have any effect. What are the column attribute types for these 2 dates. Character or numeric?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 19:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607827#M176770</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-11-27T19:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Date calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607828#M176771</link>
      <description>&lt;P&gt;&lt;SPAN&gt;numeric&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 19:49:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607828#M176771</guid>
      <dc:creator>Xinhui</dc:creator>
      <dc:date>2019-11-27T19:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Date calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607829#M176772</link>
      <description>&lt;P&gt;It's likely that you have null or missing values in your original dataset then. You'll need to either address these null/missing values or not calculate those?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 19:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607829#M176772</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-11-27T19:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Date calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607832#M176774</link>
      <description>&lt;P&gt;Is this what you're looking for?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  date="02/12/2018";
  edate="02/24/2018";
run;

data want;
set have;
format date_num edate_num date9.;
date_num = input(compress(date,"/"),mmddyy8.);
edate_num = input(compress(edate,"/"),mmddyy8.);
date_diff = edate_num-date_num;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;-unison&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 19:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607832#M176774</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-27T19:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Date calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607833#M176775</link>
      <description>&lt;P&gt;There are no missing value there, that's why I am confuse now.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there have any way that I can send the data file to you?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 19:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607833#M176775</guid>
      <dc:creator>Xinhui</dc:creator>
      <dc:date>2019-11-27T19:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Date calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607834#M176776</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final3;
set final2;
dt = input(put(date, 8. -l), yymmdd10.);
edt = input(put(edate, 8. -l), yymmdd10.);
dd = dt - edt;
run;

 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Try that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you have a date that's a number but not a SAS date,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ie 2019/11/20 is shown as the number 20191120 not a SAS date. So first convert it to a character and then re-read it as a SAS date. There are other ways to do this but this is one way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/124145"&gt;@Xinhui&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I'm attempt to calculate the days between varible 'date' and 'edate',&amp;nbsp; I used following codes:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data final3;&lt;BR /&gt;set final2;&lt;BR /&gt;dt = input(date, yymmdd10.);&lt;BR /&gt;edt = input(edate, yymmdd10.);&lt;BR /&gt;dd = dt - edt;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It works before, but for somereason, it not work anymore.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the log information shows that&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 622:12&amp;nbsp;&amp;nbsp; 623:13&lt;/P&gt;
&lt;P&gt;NOTE: Invalid argument to function INPUT at line 623 column 7.&lt;/P&gt;
&lt;P&gt;Company_Name=ARCHER-DANIELS-MIDLAND CO TICKER=ADM EDATE=20140204 Date=20100107 Price=31.23 dt=22189 edt=. dd=.&lt;/P&gt;
&lt;P&gt;_ERROR_=1 _N_=4&lt;/P&gt;
&lt;P&gt;NOTE: Invalid argument to function INPUT at line 623 column 7.&lt;/P&gt;
&lt;P&gt;Company_Name=ARCHER-DANIELS-MIDLAND CO TICKER=ADM &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;EDATE=20150203 Date=20100108&lt;/STRONG&gt;&lt;/FONT&gt; Price=30.84 dt=22189 edt=. dd=.&lt;/P&gt;
&lt;P&gt;_ERROR_=1 _N_=5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know why it not work in this case.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that maybe the format of the "date" and "edate" has some problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 20:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-calculation/m-p/607834#M176776</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-27T20:00:39Z</dc:date>
    </item>
  </channel>
</rss>

