BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GuillermoPH
Obsidian | Level 7
Hi! I'm trying to filter a data set that contains information from 2010 until yesterday. However, the goal here is to filter only data from the last month, i.e., suppose i have transactions from 10jan2018:18:29:45 to 11mar2018:14:23:39, and i only need those from 01feb2018:0:0:0 to 01mar2018:0:0:0. How can I do this? Notice I already used prompts but since this is going to be an automatic report, i need to have it hard coded without waiting for a user response in the middle of the project. Any help will be much appreciated!
1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Hi

 

You can use the INTNX function to do this, depending on how you want to use it, you could use the SAS Macro language to create the start end end values. Please note the macro variables currently just contain the correct string representation to actually make a proper date value out of it, you need to put them into quotes and add the DT so that in the end, you get "01FEB2018:00:00:00"dt

 

%let currentDT = %sysfunc( datetime() );
%let prevMonthStart = %sysfunc( intnx(DTMONTH, &currentDT, -1, B), datetime19.);
%let prevMonthEnd = %sysfunc( intnx(DTMONTH, &currentDT, 0, B), datetime19.);


%put &=prevMonthStart &=prevMonthEnd;

or your filter expression in a query looks like

 

t1.dt BETWEEN intnx("DTMONTH", datetime(), -1, "B") AND intnx("DTMONTH", datetime(), 0, "B")

View solution in original post

2 REPLIES 2
BrunoMueller
SAS Super FREQ

Hi

 

You can use the INTNX function to do this, depending on how you want to use it, you could use the SAS Macro language to create the start end end values. Please note the macro variables currently just contain the correct string representation to actually make a proper date value out of it, you need to put them into quotes and add the DT so that in the end, you get "01FEB2018:00:00:00"dt

 

%let currentDT = %sysfunc( datetime() );
%let prevMonthStart = %sysfunc( intnx(DTMONTH, &currentDT, -1, B), datetime19.);
%let prevMonthEnd = %sysfunc( intnx(DTMONTH, &currentDT, 0, B), datetime19.);


%put &=prevMonthStart &=prevMonthEnd;

or your filter expression in a query looks like

 

t1.dt BETWEEN intnx("DTMONTH", datetime(), -1, "B") AND intnx("DTMONTH", datetime(), 0, "B")
GuillermoPH
Obsidian | Level 7
Thanks a lot Bruno_SAS! It worked beautifully, I used the second option since I'm working on queries. Regards,

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 2 replies
  • 2237 views
  • 1 like
  • 2 in conversation