Help using Base SAS procedures

Using macro date range

Reply
Contributor
Posts: 59

Using macro date range

proc sql;

create table pay1 as

select id, due_date

from table1

quit;

data pay2;

set pay1;

BreakDate=due_date+5 /*Example if the due_date is 05/25/2013 this variable returns 05/30/13*/

run;

My question is, I use macro that automatically accounts for previous business day.  If a day falls on Sunday, the macro &pbd will assign a Monday date.  For example &pbd+5 will return an number value for 5 days after the previous business day.  I then can format it to look like an actual date.

I need to incorporate due_date and &pbd together to produce the next business days after the 5 days has elapsed.  For example if I use the formula in my program:

If the due_date=05/14/13,the BreakDate will equal 5/19/13, which is Sunday.  I want to default to Monday.  I need to use both the due_date and &pbd to accomplish this.  Or is there an easier way?  Perhaps just say if the BreakDate falls on Sunday, automatically increment to Monday?

Super User
Posts: 19,862

Re: Using macro date range

Posted in reply to omega1983

use intnx with the 'weekday' option. But this won't account for holidays, so if yours does then its better.

intnx('weekday', '14May2013'd, 5);

New Contributor
Posts: 2

Re: Using macro date range

Posted in reply to omega1983

how about the last logic,

If the Breakdate falls on Sunday, automatically increment to Monday.

data _null_;

break_date='19may2013'd;

if weekday(break_date)=1 then break_date=break_date+1;

put break_date date9.;

run;

Frequent Contributor
Posts: 97

Re: Using macro date range

Posted in reply to omega1983

hi ,

Try this..

data want (drop =i);
informat break_date date9.;
format  break_date date9.;
do i = 1 to (3*30);
Break_date=intnx('days','01Apr2013'd,i);
if weekday(break_date) = 1 then
break_date=intnx('days',break_date,1);

output;

i=i+4;

end;

run;

Regards,

Allu

Regular Contributor
Posts: 195

Re: Using macro date range

Posted in reply to omega1983

Hi,

It is simple by using DATA Step as follow...

data test(drop = _temp);

  format due_date break_date date9.;

  due_date = "01Jan2013"d;

  break_date = due_date + 5;

  _temp = weekday(break_date);

  if _temp = 1 then do;

     break_date = due_date + 6;

  end;

  else do;

    break_date = break_date;

  end;

run;

-Urvish

Super User
Super User
Posts: 7,076

Re: Using macro date range

Posted in reply to omega1983

What is in the macro variable &BPD ?

1) How is it formatted?  If it is formatted as DATE9. format outputs data then you can use it as a date literal in your SQL statements. For Example:  if break_date= "&BPD"d.

2) What does the value of BPD represent?  Is it one number that will apply to all observations?  If not then you need a way to get the value of BPD that is right for the current observation.  Perhaps by creating a separate table you can merge onto your data? Or a format?

Ask a Question
Discussion stats
  • 5 replies
  • 358 views
  • 0 likes
  • 6 in conversation