Hello Experts,
Do you know please the function to count the last trimesters (compared with today).
I would like to have the data only from last trimester. My code is :
data doc3;
set doc;
format k ddmmyy10.;
format k2 ddmmyy10.;
k="30sep2021"d;
k2="31dec2021"d;
if k<datepart(ma_date)<k2;
run;
I'm looking for a function beacause all time I need to change the code for last trimester (compared with today) : k="30sep2021"d;
k2="31dec2021"d;
Thank you for your help !
What you mean is a quarter.
Use the INTNX function:
k = intnx('quarter',today(),-1,'b');
k2 = intnx('quarter',today(),-1,'e');
I'm not understanding. First, trimester, what does that mean? Is it a four month period (there are three per year)?
Next, where is this trimester used in your code?
Can you give us a concrete example or two of doing this calculation?
What you mean is a quarter.
Use the INTNX function:
k = intnx('quarter',today(),-1,'b');
k2 = intnx('quarter',today(),-1,'e');
I recommend to study the documentation of the INTNX Function, where the options are described.
@SASdevAnneMarie wrote:
Thank you for the message.
The year has 4 trimestres (1 trilestres=3 months). Compared to today, I would like to test the last trimester :
k="30sep2021"d;
k2="31dec2021"d;
In my code I'm looking if my data, ma_date, is included in last trimester.
Thank you
See my other post for code. Your descriptions matches a calendar quarter, start 1 Jan, 1 Apr, 1 Jul and 1 Oct, ending 31 Mar, 30 Jun, 30 Sep and 31 Dec. So the Intnx function in my other example at the end is what you want.
Please define exactly what YOU mean by "trimester". That can have enough differences between subject areas that a precised discussion of what you mean will help. For example prenatal examines and schools do not use "trimester" at all in the same way.
Do you intend this code to adjust based on the day that it executes?
This likely indicates the function INTNX is you choice as you can specify intervals to adjust a date from.
Here a brief example that may get close:
data example; d = today(); format d date9.; d3monthsago_b = intnx('month',d,-3,'b'); d3monthsago_e = intnx('month',d,-3,'e'); d3monthsago_s = intnx('month',d,-3,'s'); d1qtrago_e = intnx('quarter',d,-1,'e'); d2qtrago_e = intnx('quarter',d,-2,'e'); format d: date9.; run;
Running this in early March 2022, the first three variables return different days in Dec 2021, the beginning of the month, end of the month and the same of the month.
The last two variables get the END of the calendar quarters 1 and 2 quarters before today's date. Today that means 31DEC2021 and 30SEP2021.
You seem to be having a translation issue. It appears (from my limited ability to understand French websites) that it is a common meaning French to use trimestre as meaning a three month period. I cannot figure out if they actually use it to mean specifically the four three month periods in a calendar year or ANY three month period.
In English trimester is used to in pregnancy to divide the 9 months of a pregnancy into three (hence tri) periods. Since a normal pregnancy is close to 9 months this does mean that each trimester is about three months long. It is also used by some academic institutions where they divide the academic year in the three periods. Which again could be close to three months each, depending on the time between terms and whether there is any summer vacation.
Trimester would not normally be considered something your would apply to a full year If you applied it to a full calendar year then the logical meaning would be four months since that would divide the year into three periods.
When you divide something into four periods just use quarter instead. Just like when you divide something into two periods you can use half. First half of the year. First quarter of the year. etc.
So you need to use the QTR interval with the INTNX() function.
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.