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

Trying to create a month to date filter where all data is rolled up to the previous days date. Our data is updated hourly so it keeps pulling in the current days data, which I don't need.

 

The filter is written:

 

Case when YEAR(t1.Order_Dt)=YEAR(TODAY()-1) AND MONTH(t1.Order_Dt)=MONTH(TODAY()-1) then 'MTD' else 'NoMonth' end 

 

It still keep pulling in data from the current business day. What am I doing wrong???

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Look at something like

t1.order_dt between intnx('month',today()-1,0,'B') and (today()-1 )

 

You are getting todays date most of the time because month(today()-1) is month(today()) unless you are running on the first day of the month. You would also have to extend the the logic to day(order_dt) le day(today()-1)

View solution in original post

5 REPLIES 5
Reeza
Super User

Wouldn't it just be:

 

where t.order_dt < today()-1
Tihannah
Obsidian | Level 7
I need to roll up everything within the current month. t1.order_dt < today()-1 when just give me all previos data going back 2 years.
ballardw
Super User

Look at something like

t1.order_dt between intnx('month',today()-1,0,'B') and (today()-1 )

 

You are getting todays date most of the time because month(today()-1) is month(today()) unless you are running on the first day of the month. You would also have to extend the the logic to day(order_dt) le day(today()-1)

Tihannah
Obsidian | Level 7
Thank you!!
ShiroAmada
Lapis Lazuli | Level 10
data SAMPLE(where=(dates<=intnx('days',today(),-1)));
format dates date9.;
do dates '01Jan2017'd to '31Dec2017'd;
output;
end;
run;

Try this one.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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