BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
rrmenon
Fluorite | Level 6
Spoiler
 
PROC SQL;
SELECT sum(t1.TheoWin) FROM TDCX.vVW_DWH_PTNSlots t1 
JOIN TDCX.vCXComps t2
ON t1.PtnId=t2.ptnid 
WHERE (t1.DateTimeIn BETWEEN t2.compDate AND INTNX('month', t2.compDate, 1))
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Please be always specific what's not working - like returning an Error (please share log) or just not returning the expected result.

 

Does DateTimeIn store a SAS Date or DateTime value? Same goes for variable compDate.

 

Assuming DateTimeIn stores a datetime and compDate a Date value the expression needs to look like:

WHERE (datepart(t1.DateTimeIn) BETWEEN t2.compDate AND INTNX('month', t2.compDate, 1,'b'))

 

Or if these are both SAS DateTime values then you would need to use a datetime directive for intnx()

WHERE (t1.DateTimeIn BETWEEN t2.compDate AND INTNX('DTmonth', t2.compDate, 1,'b'))

 

INTNX({interval<multiple><.shift-index>}, start-from, increment<, 'alignment'>)

I would also always add the alignment explicitly. (The default is Beginning which I assume is what you want). 

Also be aware that that the BETWEEN operator is inclusive meaning the upper boundary (date start of next month) will be included into the selection.

 

 

 

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

Please be always specific what's not working - like returning an Error (please share log) or just not returning the expected result.

 

Does DateTimeIn store a SAS Date or DateTime value? Same goes for variable compDate.

 

Assuming DateTimeIn stores a datetime and compDate a Date value the expression needs to look like:

WHERE (datepart(t1.DateTimeIn) BETWEEN t2.compDate AND INTNX('month', t2.compDate, 1,'b'))

 

Or if these are both SAS DateTime values then you would need to use a datetime directive for intnx()

WHERE (t1.DateTimeIn BETWEEN t2.compDate AND INTNX('DTmonth', t2.compDate, 1,'b'))

 

INTNX({interval<multiple><.shift-index>}, start-from, increment<, 'alignment'>)

I would also always add the alignment explicitly. (The default is Beginning which I assume is what you want). 

Also be aware that that the BETWEEN operator is inclusive meaning the upper boundary (date start of next month) will be included into the selection.

 

 

 

SASKiwi
PROC Star

If TDCX points to an external database then it's quite possible INTNX won't get translated correctly into that database's SQL dialect. Id suggest trying SQL Passthru if you are reading an external database.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 629 views
  • 1 like
  • 3 in conversation