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
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.
Intnx('month',date,-3,'s')
will do this calculation.
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
Hello @Reeza ,
Thank you for the response.
Considering the oldest date = 06oct2019, could you help with the code.
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.
Hello Reeza,
Thank you for the solution.
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!
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.
Ready to level-up your skills? Choose your own adventure.