Welcome to the wonderful world of SAS! According to my calculations, 12 months back from Apr 2024 should be Apr 2023 but maybe there's a reason you need to include the previous month as well. Regardless, the calculation would require the INTNX function which allows you to backtrack by a given time interval, say month. Documentation here: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p10v3sa3i4kfxfn1sovhi5xzxh8n.htm
Here's an example:
data dates;
run_date='23apr2024'd;
back12months_date=intnx('month',run_date,-12,'B')+19;
format run_date back12months_date date9.;
run;
The INTNX function uses 4 arguments here:
The time interval you want to increment/decrement by ("month")
The starting point (run_date)
The increment/decrement value (12 months back would be specified as -12)
The alignment (we will align to the beginning of the month using "B")
I've added 19 days to this calculation to get us to the 20th of the month.
You could also make this dynamic by having run_date reference today's date:
data dates;
run_date=today();
back12months_date=intnx('month',run_date,-12,'B')+19;
format run_date back12months_date date9.;
run;
which will return back12months_date as 20APR2024.
... View more