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

The purpose is to query a set of records within a day and do the same query repetitively one year back at a time.

Tom
Super User Tom
Super User

@DavidPhillips2 wrote:

The purpose is to query a set of records within a day and do the same query repetitively one year back at a time.


That is not what the code you posted is doing. It is getting the data for a single day.  Then you are trying to change to the first day of the year before and are getting the data for that January 1st day.  To go back exactly a year you need to use SAME as the last parameter to the INTNX() function call.

 

Do you want the data grouped by day?  Why not just create a DATE value from your DATETIME values?

Do you want the data grouped by year?

Do you want a rolling interval of 365 (366) days?

 

DavidPhillips2
Rhodochrosite | Level 12

I'm querying today's date to see what datetimes stored in the large transaction table fall within today's date.  The feeding the two date ranges into a where clause.

 

If I use the number of seconds from 1960, how do I insert the result into a where clause and increment it back a year.

ballardw
Super User

@DavidPhillips2 wrote:

I'm querying today's date to see what datetimes stored in the large transaction table fall within today's date.  The feeding the two date ranges into a where clause.

 

If I use the number of seconds from 1960, how do I insert the result into a where clause and increment it back a year.


Same as changing a date by a year, use the INTNX function. Use interval DTYEAR so SAS know you are incrementing a datetime value.

 

data example;
   x= dhms(today(),9,15,20);
   format x datetime20.;
   y1 = intnx('dtyear',x,-1,'b');
   y2 = intnx('dtyear',x,-1,'s');
   y3 = intnx('dtyear',x,-1,'e');
   format y: datetime20.;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 18 replies
  • 2510 views
  • 6 likes
  • 4 in conversation