BookmarkSubscribeRSS Feed
hdg
Obsidian | Level 7 hdg
Obsidian | Level 7


Hi,

I am looking to populate a dataset with the next quarters upto todays date, the quarter date populated should be the last Friday of that quarter

%let mydate = "25Mar2011"d

Output

date

25 Mar 2011

24 Jun 2011

30 Dec 2011

30 Mar 2012

Thanks for all your help.

8 REPLIES 8
Haikuo
Onyx | Level 15

Try this one, the functions are simple, but looks complicated when being nested:

%let mydate = "25Mar2011"d

;

data want;

format date date9.;

retain date 0;

do _n_=0 by 1 while (date <= intnx('qtr',today(),-1,'s'));

date=ifn(weekday(&mydate)=5, &mydate, intnx('week.7',intnx('qtr',&mydate,_n_,'e'),-1,'e'));

output;

end;

run;

proc print;run;

Haikuo

data_null__
Jade | Level 19

I don't think it can be done with just one INTNX.  I find the last day of interval and then find the Friday by incrementing the interval by 0 using a shifted WEEK interval.  Of course the functions could be nested into one statement.

data _null_;

  s="25Mar2011"d;

   do i=0 by 1;

      q = intnx('qtr',s,i,'e');

      f = intnx('week.6',q,0); *last Friday of quarter;

      if f gt today() then leave;

      put (q f) (weekdate. +3);

      end;

   run;

hdg
Obsidian | Level 7 hdg
Obsidian | Level 7

Sorry for not being more clear in my example,  the quarter should depend on your starting date. I have been getting confused with the qrtr/intnx command. Since it should not just be calendar year quarters.

So say Feb 2012

would be May 2012

etc

Haikuo
Onyx | Level 15

Actually what you have just said makes me confused. You need to define the start and end day of each quarter. say for 05Feb2012, is 1feb2012 being the start day and 31may2012 being the end day or 05feb2012 being the start day and 05may2012 being the end day?

Thanks,

Haikuo

hdg
Obsidian | Level 7 hdg
Obsidian | Level 7

Sorry Haikuo and thanks for all your help! Maybe a worked example will make it more clear

%let mydate = "25Nov2011"d -- this is last friday of november

Output dataset alldates

date

25Nov2011

24Feb2012

Another example ie previous one

%let mydate = "25Mar2011"d

Output dataset alldates

date

25 Mar 2011

24 Jun 2011

30 Dec 2011

30 Mar 2012

%let mydate =


Haikuo
Onyx | Level 15

A minor tweak on my previous code should do:

%let mydate = "25Nov2011"d

;

data want;

format date date9.;

retain date 0;

do _n_=0 by 1 while (date <= intnx('qtr',today(),-1,'s'));

date=ifn(weekday(&mydate)=5, &mydate, intnx('week.7',intnx('month',&mydate,3*_n_,'e'),-1,'e'));

output;

end;

run;

proc print;run;

Good Luck!

Haikuo

Linlin
Lapis Lazuli | Level 10

%let mydate = "25mar2011"d;

data want;

format date date9.;

retain date 0;

do _n_=0 by 3 while (date <= intnx('qtr',today(),-1,'s'));

date=intnx('month',&mydate,_n_,'e');

week= intnx('week.6', date,0);

format week date9.;

output;

end;

proc print;run;

Ksharp
Super User

How about:

%let mydate = "25nov2011"d;
data want(keep=date);
date=&mydate;output; 
   do until(_d gt "20apr2012"d);
    _d = intnx('month',date,3,'e'); 
    date = intnx('week.6',_d,0,'b'); *last Friday of quarter;
    if date le "20apr2012"d then output;
   end;
format date date9.;
run;

Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 1954 views
  • 1 like
  • 5 in conversation