BookmarkSubscribeRSS Feed
omega1983
Calcite | Level 5

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?

5 REPLIES 5
Reeza
Super User

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);

Arul
Calcite | Level 5

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;

allurai0412
Fluorite | Level 6

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

UrvishShah
Fluorite | Level 6

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

Tom
Super User Tom
Super User

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?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1199 views
  • 0 likes
  • 6 in conversation