BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mushy
Quartz | Level 8

Hello All,

 

I have a situation where I need to report on quarterly basis.

I need to manipulate the quarters considering the current date.

So if today is 06OCT, I need a Quarter format that represents 3 months, from now to minus 3 three months... say the latest quarter should have values for the date 06 JUL to 06 OCT. So the format should dynamically determine the 3 months cut off. Is there a predefined method for this in SAS or anyone could help in how this could be achieved?

 

Thanks

Mushy

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data date_format;
start_date=today();

fmtname = 'custom_qtr_fmt';
type = 'N';

n_intervals = intck('quarters',  '06Oct2019'd, start_date);

do i=1 to n_intervals;
end = intnx('quarter', start_date, -1*(i-1), 's');
start = intnx('quarter', start_date, -1*(i), 's');
label = catx(" - ", put(start, date9.), put(end, date9.));
output;
end;

format start: end: date9.;

run;

proc format cntlin = date_format;
run;

Then apply as needed within the proc.

View solution in original post

6 REPLIES 6
Mushy
Quartz | Level 8

Hello Kurt,

 

Thanks for responding.

But I need the format applied to all the historical data as well.

say we have date for 2 years. I need to fit a format defines for each 3 previous months from today.

 

Thanks,

Mushy

Reeza
Super User
I would build a dynamic format using a loop. So figure out the period you're reporting for, ie - how far back does the dates need to go, and build a custom format each month using CNTLIN.

Do you know how to loop and use INTNX()?
Mushy
Quartz | Level 8

Hello @Reeza ,

Thank you for the response.

Considering the oldest date = 06oct2019, could you help with the code.

 

 

Reeza
Super User
data date_format;
start_date=today();

fmtname = 'custom_qtr_fmt';
type = 'N';

n_intervals = intck('quarters',  '06Oct2019'd, start_date);

do i=1 to n_intervals;
end = intnx('quarter', start_date, -1*(i-1), 's');
start = intnx('quarter', start_date, -1*(i), 's');
label = catx(" - ", put(start, date9.), put(end, date9.));
output;
end;

format start: end: date9.;

run;

proc format cntlin = date_format;
run;

Then apply as needed within the proc.

Mushy
Quartz | Level 8

Hello Reeza, 

Thank you for the solution.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1150 views
  • 4 likes
  • 3 in conversation