<?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 Working on Dates in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Working-on-Dates/m-p/7524#M114</link>
    <description>Hello&lt;BR /&gt;
In a dataset, how can I ask the following&lt;BR /&gt;
I enter 2 dates variables for this year like 01mar08 and 31mar08 being &amp;amp;date1 and &amp;amp;date2&lt;BR /&gt;
I xant to get same info for last year so I wrote : &amp;amp;date1 - 365&lt;BR /&gt;
Unfortunately, with 29feb08, I get a wrong date . . .&lt;BR /&gt;
I suppose I have to interpret it as "Mar-08" minus 12 months but how do I do ?&lt;BR /&gt;
Many thanks in advance&lt;BR /&gt;
Joël</description>
    <pubDate>Mon, 17 Mar 2008 13:34:48 GMT</pubDate>
    <dc:creator>joel</dc:creator>
    <dc:date>2008-03-17T13:34:48Z</dc:date>
    <item>
      <title>Working on Dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Working-on-Dates/m-p/7524#M114</link>
      <description>Hello&lt;BR /&gt;
In a dataset, how can I ask the following&lt;BR /&gt;
I enter 2 dates variables for this year like 01mar08 and 31mar08 being &amp;amp;date1 and &amp;amp;date2&lt;BR /&gt;
I xant to get same info for last year so I wrote : &amp;amp;date1 - 365&lt;BR /&gt;
Unfortunately, with 29feb08, I get a wrong date . . .&lt;BR /&gt;
I suppose I have to interpret it as "Mar-08" minus 12 months but how do I do ?&lt;BR /&gt;
Many thanks in advance&lt;BR /&gt;
Joël</description>
      <pubDate>Mon, 17 Mar 2008 13:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Working-on-Dates/m-p/7524#M114</guid>
      <dc:creator>joel</dc:creator>
      <dc:date>2008-03-17T13:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Working on Dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Working-on-Dates/m-p/7525#M115</link>
      <description>Hi:&lt;BR /&gt;
  That's really strange. When I subtract 365 from the internal value for 29Feb08 (17591) , I get the internal value for 03/01/2007 (17226). Depending on how you're handling and using your macro variables, you may not have the macro variable in the correct numeric form for doing the subtraction. If &amp;amp;DATE1 resolves to the TEXT string 29Feb08, then it's not really a SAS date value -- it's just a text string that happens to look like a date. Your text string has to be recognized as the number of days since Jan 1, 1960 in order for your subtraction to work correctly. &lt;BR /&gt;
 &lt;BR /&gt;
  I've inserted some test code below. Your best bet for help is to contact Tech Support so they can look at ALL of your code --  where the macro variables are set and how/where you're performing the subtraction so they can help you with the correct syntax. As you can see in the code below, you would do the subtraction slightly differently in ALL macro versus inside the DATA step program.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
** All macro;&lt;BR /&gt;
%let date1=29Feb08;&lt;BR /&gt;
%let date2=31Dec08;&lt;BR /&gt;
%put ------------------***;&lt;BR /&gt;
%put date1 is: &amp;amp;date1;&lt;BR /&gt;
%put date2 is: &amp;amp;date2;&lt;BR /&gt;
    &lt;BR /&gt;
%put ------------------***;&lt;BR /&gt;
%let dateval = %sysfunc(inputn(&amp;amp;date1,date7.));&lt;BR /&gt;
%let calc = %eval(&amp;amp;dateval - 365);&lt;BR /&gt;
%put dateval is: &amp;amp;dateval;&lt;BR /&gt;
%put calc is: &amp;amp;calc;&lt;BR /&gt;
    &lt;BR /&gt;
%let yearago1 = %sysfunc(putn(&amp;amp;calc,mmddyy10.));&lt;BR /&gt;
%put ******* yearago1 is: &amp;amp;yearago1;&lt;BR /&gt;
   &lt;BR /&gt;
** use in DATA step program;&lt;BR /&gt;
data testmacvar;&lt;BR /&gt;
  d_date1 = "&amp;amp;date1"d;&lt;BR /&gt;
  d_date2 = "&amp;amp;date2"d;&lt;BR /&gt;
  yearago1 = "&amp;amp;date1"d - 365;&lt;BR /&gt;
  yearago2 = "&amp;amp;date2"d - 365;&lt;BR /&gt;
  format d_date1 d_date2 yearago1 yearago2 mmddyy10.;&lt;BR /&gt;
run;&lt;BR /&gt;
     &lt;BR /&gt;
options nocenter;&lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print data=testmacvar;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
SAS Log &amp;amp; output:&lt;BR /&gt;
[pre]&lt;BR /&gt;
198  %let date1=29Feb08;&lt;BR /&gt;
199  %let date2=31Dec08;&lt;BR /&gt;
200  %put ------------------***;&lt;BR /&gt;
------------------***&lt;BR /&gt;
201  %put date1 is: &amp;amp;date1;&lt;BR /&gt;
date1 is: 29Feb08&lt;BR /&gt;
202  %put date2 is: &amp;amp;date2;&lt;BR /&gt;
date2 is: 31Dec08&lt;BR /&gt;
203&lt;BR /&gt;
204  %put ------------------***;&lt;BR /&gt;
------------------***&lt;BR /&gt;
205  %let dateval = %sysfunc(inputn(&amp;amp;date1,date7.));&lt;BR /&gt;
206  %let calc = %eval(&amp;amp;dateval - 365);&lt;BR /&gt;
207  %put dateval is: &amp;amp;dateval;&lt;BR /&gt;
dateval is: 17591&lt;BR /&gt;
208  %put calc is: &amp;amp;calc;&lt;BR /&gt;
calc is: 17226&lt;BR /&gt;
209&lt;BR /&gt;
210  %let yearago1 = %sysfunc(putn(&amp;amp;calc,mmddyy10.));&lt;BR /&gt;
211  %put ******* yearago1 is: &amp;amp;yearago1;&lt;BR /&gt;
******* yearago1 is: 03/01/2007&lt;BR /&gt;
212&lt;BR /&gt;
213  title; footnote;&lt;BR /&gt;
214  data testmacvar;&lt;BR /&gt;
215    d_date1 = "&amp;amp;date1"d;&lt;BR /&gt;
216    d_date2 = "&amp;amp;date2"d;&lt;BR /&gt;
217    yearago1 = "&amp;amp;date1"d - 365;&lt;BR /&gt;
218    yearago2 = "&amp;amp;date2"d - 365;&lt;BR /&gt;
219    format d_date1 d_date2 yearago1 yearago2 mmddyy10.;&lt;BR /&gt;
220  run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: The data set WORK.TESTMACVAR has 1 observations and 4 variables.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
************************ OUTPUT *************************&lt;BR /&gt;
Obs       d_date1       d_date2      yearago1      yearago2&lt;BR /&gt;
&lt;BR /&gt;
 1     02/29/2008    12/31/2008    03/01/2007    01/01/2008&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 17 Mar 2008 14:12:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Working-on-Dates/m-p/7525#M115</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-03-17T14:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: Working on Dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Working-on-Dates/m-p/7526#M116</link>
      <description>You could use&lt;BR /&gt;
&lt;BR /&gt;
MDY(MONTH(&amp;amp;date1),DAY(&amp;amp;date1),YEAR(&amp;amp;date1)-1)&lt;BR /&gt;
&lt;BR /&gt;
Just a thought.&lt;BR /&gt;
&lt;BR /&gt;
Ike

Message was edited by: WDEisenhauer</description>
      <pubDate>Mon, 17 Mar 2008 14:29:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Working-on-Dates/m-p/7526#M116</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-03-17T14:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: Working on Dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Working-on-Dates/m-p/7527#M117</link>
      <description>Hello Cynthia&lt;BR /&gt;
I guess, I wrongly wrote my question&lt;BR /&gt;
basically, my first date is "01mar08"d and I want to get "01mar07"d or one year ago; in the past I simply did : "01feb08"d - 365 and I got exactly the date last year&lt;BR /&gt;
After leapday 29feb08 and, as from 01mar08 I get 02mar07 !&lt;BR /&gt;
I just want to use a way (a function ?) to do it !&lt;BR /&gt;
Sorry for probably boring question ! &lt;BR /&gt;
But thanks again for help !!!&lt;BR /&gt;
Joël</description>
      <pubDate>Mon, 17 Mar 2008 14:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Working-on-Dates/m-p/7527#M117</guid>
      <dc:creator>joel</dc:creator>
      <dc:date>2008-03-17T14:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: Working on Dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Working-on-Dates/m-p/7528#M118</link>
      <description>Hello Ike&lt;BR /&gt;
Yes, it works fine and solves my problem !&lt;BR /&gt;
Many thanks for your help &lt;BR /&gt;
Joël</description>
      <pubDate>Mon, 17 Mar 2008 14:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Working-on-Dates/m-p/7528#M118</guid>
      <dc:creator>joel</dc:creator>
      <dc:date>2008-03-17T14:36:13Z</dc:date>
    </item>
  </channel>
</rss>

