Help using Base SAS procedures

Create table showing last friday of month

Accepted Solution Solved
Reply
Super Contributor
Posts: 259
Accepted Solution

Create table showing last friday of month

I'm trying to create a macro that creates a table showing the last Friday of every month. The table will look like this:

So, if i select a range of years, say 2001 to 2013 it will create a table like this:

YEARMONTHLASTFRIDAY
20130222
20130329
20130426
201305...
201306...
201307...
201308...
......
......

including all the years in the range I specify.


Accepted Solutions
Solution
‎08-01-2014 08:03 AM
Respected Advisor
Posts: 3,777

Re: Create table showing last friday of month

This seem reasonable, I always have to experiment with shifted intervals a bit before I can figure it.   Find the last day of the month then find the first day of the week that "begins" on Friday "WEEK.6".

data friday;
   do year=2001 to 2013;
     
do month = 1 to 12;
         b = mdy(month,
1,year);
         e = intnx('Month',b,0,'E');
         f = intnx('week.6',e,0,'B');
         output;
        
end;
     
end;
  
format b e f weekdate.;
  
run;
proc print;
  
run;

8-1-2014 7-03-00 AM.png

View solution in original post


All Replies
Super User
Super User
Posts: 7,401

Re: Create table showing last friday of month

Hi,


You would be best served using the interval functions an example is here:

SAS/ETS(R) 9.2 User's Guide

Solution
‎08-01-2014 08:03 AM
Respected Advisor
Posts: 3,777

Re: Create table showing last friday of month

This seem reasonable, I always have to experiment with shifted intervals a bit before I can figure it.   Find the last day of the month then find the first day of the week that "begins" on Friday "WEEK.6".

data friday;
   do year=2001 to 2013;
     
do month = 1 to 12;
         b = mdy(month,
1,year);
         e = intnx('Month',b,0,'E');
         f = intnx('week.6',e,0,'B');
         output;
        
end;
     
end;
  
format b e f weekdate.;
  
run;
proc print;
  
run;

8-1-2014 7-03-00 AM.png
Contributor
Posts: 23

Re: Create table showing last friday of month

data _null_, shifted intervals are easy if you remember that interval.1 is the same as interval. It only gets complicated when you have large multipliers.

Super User
Posts: 9,681

Re: Create table showing last friday of month

NULL,

Don't forget function  nwkdom( ) .

data friday;
   do year=2001 to 2013; 
      do month = 1 to 12; 
           date=nwkdom(5,6,month,year);
           output; 
         end; 
      end; 
   format date weekdate.; 
   run; 


Xia Keshan

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1072 views
  • 6 likes
  • 5 in conversation