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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 6 replies
  • 779 views
  • 4 likes
  • 3 in conversation