<?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 Change dates format then get the difference between them. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588695#M168282</link>
    <description>&lt;P&gt;Hi, need some help with two variables, both displaying dates in the following format: DDMMYYYY. (Using SAS UE)&lt;BR /&gt;&lt;BR /&gt;Example:&lt;BR /&gt;&amp;nbsp;- DTOBITO = 04062017, which means "04jun2017"&lt;BR /&gt;&amp;nbsp;- DTNASC = 06062017, which means "06jun2017"&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;What i need to do is find a way to get the difference(in days) between DTOBITO and DTNASC , like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var3 = DTOBITO - DTNASC.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the example, var3 should be equal to 2.&lt;BR /&gt;&lt;BR /&gt;Im using a dbf file, so im not certain about the format of this variable, if its numeric ou char variables.&lt;/P&gt;</description>
    <pubDate>Sat, 14 Sep 2019 03:18:32 GMT</pubDate>
    <dc:creator>missaka</dc:creator>
    <dc:date>2019-09-14T03:18:32Z</dc:date>
    <item>
      <title>Change dates format then get the difference between them.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588695#M168282</link>
      <description>&lt;P&gt;Hi, need some help with two variables, both displaying dates in the following format: DDMMYYYY. (Using SAS UE)&lt;BR /&gt;&lt;BR /&gt;Example:&lt;BR /&gt;&amp;nbsp;- DTOBITO = 04062017, which means "04jun2017"&lt;BR /&gt;&amp;nbsp;- DTNASC = 06062017, which means "06jun2017"&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;What i need to do is find a way to get the difference(in days) between DTOBITO and DTNASC , like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var3 = DTOBITO - DTNASC.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the example, var3 should be equal to 2.&lt;BR /&gt;&lt;BR /&gt;Im using a dbf file, so im not certain about the format of this variable, if its numeric ou char variables.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Sep 2019 03:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588695#M168282</guid>
      <dc:creator>missaka</dc:creator>
      <dc:date>2019-09-14T03:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Change dates format then get the difference between them.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588697#M168284</link>
      <description>&lt;P&gt;Assuming they are simple numbers:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
DTOBITO = 04062017;
DTNASC = 06062017;
DT_OBITO = mdy(mod(int(DTOBITO/10000),100), int(DTOBITO/1000000), mod(DTOBITO, 10000));
DT_NASC = mdy(mod(int(DTNASC/10000),100), int(DTNASC/1000000), mod(DTNASC, 10000));
format DT_: yymmdd10.;
diff = DT_NASC - DT_OBITO;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs. 	DTOBITO 	DTNASC 	DT_OBITO 	DT_NASC 	diff
1 	4062017 	6062017 	2017-06-04 	2017-06-06 	2&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Sep 2019 04:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588697#M168284</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-09-14T04:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Change dates format then get the difference between them.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588713#M168292</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	DTOBITO=04062017;
	DTNASC=06062017;

	_DTOBITO=input(put(DTOBITO, $8.), ddmmyy8.);
	_DTNASC=input(put(DTNASC, $8.), ddmmyy8.);

	diff=_DTNASC-_DTOBITO;

	put diff=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Sep 2019 08:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588713#M168292</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-14T08:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Change dates format then get the difference between them.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588714#M168293</link>
      <description>&lt;P&gt;Alternatively please try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
DTOBITO=04062017;
DTNASC =06062017;
DT_OBITO=input(strip(prxchange('s#(\d{1,2})(\d{2})(\d{4})#$3-$2-$1#',-1,put(DTOBITO,best.))),yymmdd10.);
DT_NASC=input(strip(prxchange('s#(\d{1,2})(\d{2})(\d{4})#$3/$2/$1#',-1,put(DTNASC,best.))),yymmdd10.);
format DT_: yymmdd10.;
diff = DT_NASC - DT_OBITO;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Sep 2019 08:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588714#M168293</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-09-14T08:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: Change dates format then get the difference between them.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588723#M168300</link>
      <description>&lt;P&gt;Proc Contents will show you if the variables are numeric or character. Once you know this I'd go for an approach where you first convert the strings or numbers into a SAS date value as then you can simply substract the dates from each other.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;posted an approach for numeric SAS variables. If they are character then simply omit the put() statement part in the the code (which converts the numerical vars to a string before reading the string into SAS as a SAS date value).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Sep 2019 12:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588723#M168300</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-09-14T12:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Change dates format then get the difference between them.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588735#M168306</link>
      <description>&lt;P&gt;Are you sure they are not already dates that are just using a format that makes them appear in that style?&lt;/P&gt;
&lt;P&gt;Run PROC&amp;nbsp; CONTENTS on your SAS dataset and check if the variable is numeric or character and if it is numeric what (if any) format is attached to it.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Sep 2019 16:23:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588735#M168306</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-14T16:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: Change dates format then get the difference between them.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588766#M168319</link>
      <description>&lt;P&gt;I wish i could select more than one reply as accepted solution. &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; You and&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304" target="_blank"&gt;@draycut&lt;/A&gt;&amp;nbsp;resolved the problem. Thank you very much.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I still had a doubt about part of the code:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The "proc contents" show me that all vars were type Char. When i run the code with the "put diff=" line, i get a&amp;nbsp;"&lt;SPAN&gt;WARNING: Maximum log size exceeded." message. If i comment the&amp;nbsp;"put diff=" line, the warning disapears and the results remains the same. What is the purpose of this line?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Sep 2019 21:08:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/588766#M168319</guid>
      <dc:creator>missaka</dc:creator>
      <dc:date>2019-09-14T21:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Change dates format then get the difference between them.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/589156#M168457</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/280708"&gt;@missaka&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I wish i could select more than one reply as accepted solution. &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; You and&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304" target="_blank" rel="noopener"&gt;@draycut&lt;/A&gt;&amp;nbsp;resolved the problem. Thank you very much.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I still had a doubt about part of the code:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The "proc contents" show me that all vars were type Char. When i run the code with the "put diff=" line, i get a&amp;nbsp;"&lt;SPAN&gt;WARNING: Maximum log size exceeded." message. If i comment the&amp;nbsp;"put diff=" line, the warning disapears and the results remains the same. What is the purpose of this line?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you have a line in a data step like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;put diff=;&lt;/P&gt;
&lt;P&gt;then when the code you will display the value of the variable(s) in the log&amp;nbsp;each time the instruction is encountered. One very common use of the Put is debugging a program, checking on values at one or more places in the execution to see if the code is doing what is expected. The put statement can also be used to write more interesting messages or write to an external file with lots of text control.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The put could&amp;nbsp;execute once, or more times,&amp;nbsp;per record in your data. If you have something like that inside a do loop&amp;nbsp; in the data step you get one line put&amp;nbsp;to the log&amp;nbsp;per execution of the loop.&lt;/P&gt;
&lt;P&gt;If you put enough lines then you can exceed the amount of memory that the log is intended to hold. So you get a warning like that. Removing the put means you aren't writing all that information in the log and so don't get the warning.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 18:29:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dates-format-then-get-the-difference-between-them/m-p/589156#M168457</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-16T18:29:58Z</dc:date>
    </item>
  </channel>
</rss>

