Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make macros out of dates

Status
Not open for further replies.

Queryman

Programmer
Nov 4, 2002
243
US
I need to make two global macros
Svcdte1 should be current_date minus 189 days
Svcdte2 should be current_date
and both macros need to be in this format '2002-11-25'
Thanks!

QueryMan

 
Hi Queryman,

date minus 189 days sounds weird - homework?

Cheers,
Matthias
 
No, not homework, haven't had to do that in about 20 years...I need to get this done to automate a piece of code at work where we select claims for a range of six months plus a week, so it's 182 days plus 7 days to total 189.

QueryMan

 
Hi again,

let's see if I get that right:

Code:
data _null_;
   call symput ("SVCDTE1", put (intnx('day', today(), -189), yymmdd10.));
   call symput ("SVCDTE2", put (today(), yymmdd10.));
run;
%put &SVCDTE1.;
%put &SVCDTE2.;


Output looks like this:

Code:
%put &SVCDTE1.;
2002-05-22
%put &SVCDTE2.;
2002-11-27

Cheers,
Matthias
 
Matthias,
If I need the macro to resolve to '2002-05-22' instead of 2002-05-22, what change would I need to make.
Thanks!

QueryMan

 
Hi,

just surround by single quotes on the assignment of the values:

Code:
   call symput ("SVCDTE1", "'" || put (intnx('day', today(), -189), yymmdd10.) || "'");
   call symput ("SVCDTE2", "'" || put (today(), yymmdd10.) || "'");

Cheers,
Matthias
 
I have a follow up question...
My boss wants this changed to count 182 days back from the last Saturday. So if today is Friday or Sat, this should count back 182 days from last Sat, but if today is anytime after midnight Sat (Sun Morning etc..) it should count back 182 days from this Saturday.

QueryMan

 
Hi Queryman,

your boss giving me a hard time, man ;-)

Okay, SAS has a Weekday() function, Sunday=1, .. Saturday=7. Should then look like - no guarantee, you have to play with it (181 or 182?), I am off heading home, still checking tek-tips over the weekend, I stop blurping, here's the code:

Code:
data _null_;
   td = today();
   call symput ("SVCDTE1", "'" || put (intnx('day', td, -(181+weekday(td))), yymmdd10.) || "'");
   call symput ("SVCDTE2", "'" || put (td, yymmdd10.) || "'");
run;
%put &SVCDTE1;
%put &SVCDTE2;

Output:

Code:
80   %put &SVCDTE1;
'2002-05-26'
81   %put &SVCDTE2;
'2002-11-29'

What's the hourly rate at your company? (just kidding)

Have a great weekend!
Matthias
 
Hi Queryman,

am home now, looked into it again, I guess the calculation is okay. You just have to carefully check if the result should be a Friday or a Saturday - for that you need to adjust the 181 factor accordingly.

Nice weekend,
Matthias
 
Hi Matthias,
Thanks for your response. Maybe I wasn't clear enough, SVCDATE1 needs to be 182 days from the previous saturday, so by default, svcdate2 will be that saturday and svcdate1 will be 182 days before that.

Example in this case since today is Friday, svcdate2 will be '2002-11-23' and svcdate1 will be '2002-05-25' (182 days)

QueryMan

 
Matthias,
I came up with this, can you think of a way to do it any easier with less code?
data _null_;
if weekday(1)then wk = weekday(1);
if weekday(2)then wk = weekday(2);
if weekday(3)then wk = weekday(3);
if weekday(4)then wk = weekday(4);
if weekday(5)then wk = weekday(5);
if weekday(6)then wk = weekday(6);
if weekday(7)then wk = weekday(0);
td = today();
call symput ("SVCDTE2", "'" || put (intnx('day', td,
-(weekday(td))), yymmdd10.) || "'");
call symput ("SVCDTE1", "'" || put (intnx('day', td,
-(182+weekday(td))), yymmdd10.) || "'");
run;
%put &SVCDTE1;
%put &SVCDTE2;

QueryMan

 
Matthias,
Please ignore my last post, it was incorrect!

QueryMan

 
This seems to work
data _null_;
td = today();
call symput ("SVCDATE1", "'" || put (intnx('day', td,-(182+weekday(td))), yymmdd10.) || "'");
call symput ("SVCDATE2", "'" || put (intnx('day', td,-(weekday(td))), yymmdd10.) || "'");run;
%put &SVCDTE1;
%put &SVCDTE2;

QueryMan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top