In a dataset, how can I ask the following
I enter 2 dates variables for this year like 01mar08 and 31mar08 being &date1 and &date2
I xant to get same info for last year so I wrote : &date1 - 365
Unfortunately, with 29feb08, I get a wrong date . . .
I suppose I have to interpret it as "Mar-08" minus 12 months but how do I do ?
Many thanks in advance
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 &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.
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.
** All macro;
%put date1 is: &date1;
%put date2 is: &date2;
%let dateval = %sysfunc(inputn(&date1,date7.));
%let calc = %eval(&dateval - 365);
%put dateval is: &dateval;
%put calc is: &calc;
%let yearago1 = %sysfunc(putn(&calc,mmddyy10.));
%put ******* yearago1 is: &yearago1;
** use in DATA step program;
d_date1 = "&date1"d;
d_date2 = "&date2"d;
yearago1 = "&date1"d - 365;
yearago2 = "&date2"d - 365;
format d_date1 d_date2 yearago1 yearago2 mmddyy10.;
I guess, I wrongly wrote my question
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
After leapday 29feb08 and, as from 01mar08 I get 02mar07 !
I just want to use a way (a function ?) to do it !
Sorry for probably boring question !
But thanks again for help !!!