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

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 !

1 ACCEPTED SOLUTION
9 REPLIES 9
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
SASdevAnneMarie
Barite | Level 11
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
SASdevAnneMarie
Barite | Level 11
Thank you, Kurt.
What does it mean, 'b' and 'e' please ?
ballardw
Super User

@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.

ballardw
Super User

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.

 

 

SASdevAnneMarie
Barite | Level 11
Thank you for the message, Ballardw
The year has 4 trimestres (1 trilestres=3 months). Compared to today, I would like to test the last trimester, beacause today we are in the first trimestr (1.01-31.03) that is not finish.
For the last trimester the dates are :
k="30sep2021"d;
k2="31dec2021"d;

In my code I'm looking if my data, ma_date, is included in last trimester or not.

Thank you
Tom
Super User Tom
Super User

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.

 

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
  • 9 replies
  • 904 views
  • 2 likes
  • 5 in conversation