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.

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!

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
  • 175 views
  • 1 like
  • 3 in conversation