## Create table showing last friday of month

Solved
Super Contributor
Posts: 261

# 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
Posts: 3,852

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

All Replies
Super User
Posts: 9,599

## 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
Posts: 3,852

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

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: 10,778

## 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 and locked.