BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sarahzhou
Quartz | Level 8

Hi,

 

The latest data_load_dt is 03NOV2022:19:57:51.251 in my system, and today is 4NOV2022 in my local time, it is near 11am now.


I want to select the data of data_load date from yesterday 7am to today 7am, that is 03NOV2022:07:00:00.000 to 04NOV2022:07:00:00.000.


How can I code the where condition?

where data_load_date<'today7am'.d and data_load_date>'yesterday7am'.d

How do I express today 7am and yesterday 7am in SAS language?

 

Previously I used today and yesterday macro as below:

%let today=%sysfunc(intnx(day,%sysfunc(today()),0),date9.);
%let yesterday=%sysfunc(intnx(day,%sysfunc(today()),-1),date9.);

However, I don't know how to add the hours into the date as a selection critical

 

Kindly advise.
Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
sarahzhou
Quartz | Level 8

Hi, I think I fixed this by

 

"&yesterday.:07:00"DT.

 

🙂

View solution in original post

2 REPLIES 2
sarahzhou
Quartz | Level 8

Hi, I think I fixed this by

 

"&yesterday.:07:00"DT.

 

🙂

Kurt_Bremser
Super User

You can do this in data step code:

where dhms(today() - 1,7,0,0) < data_load_date < dhms(today(),7,0,0)

If the "today" and "yesterday" values need to be determined independent of the result of the TODAY() function, you can use macro variables as arguments to the DHMS functions. Also see Maxim 28.

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
  • 2 replies
  • 327 views
  • 0 likes
  • 2 in conversation