BookmarkSubscribeRSS Feed
CynthiaFan
Obsidian | Level 7

Hi,

 

I have a question about how to calculate the numbers of specific days between two dates? For example, row 1 of the listed data has 34 Mondays plus Wednesdays and Saturdays between 8/29/2016 and 11/15/2016, how to program it?

 

d_start1 d_end1
8/29/2016 11/15/2016
8/29/2016 12/10/2016
8/29/2016 12/20/2016
8/29/2016 12/20/2016
8/29/2016 8/30/2016
8/29/2016 11/9/2016
8/29/2016 12/20/2016
8/29/2016 12/20/2016
8/29/2016 12/20/2016
8/29/2016 11/16/2016

 

Thank you.

 

Ying Ker

2 REPLIES 2
Astounding
PROC Star

There may be shorter ways, but brute force is always a possibility:

 

n_Mondays=0;

n_Wednesdays=0;

n_Saturdays=0;

do i=d_start to d_end;

   wd = weekday(i);

   if wd=2 then n_Mondays + 1;

   else if wd=4 then n_Wednesdays + 1;

   else if wd=7 then n_Saturdays + 1;

end;

CynthiaFan
Obsidian | Level 7

Thank you.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 878 views
  • 1 like
  • 2 in conversation