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

Using proc sql (passing teradata) I need to calculate the number of business days between two dates:

 

,intck('WEEKDAY', a.OPEN_DATE, b.DSCHRG_DT) as Num_BD_Diff  (this did not work)

 

What is the correct code to use?

 

Thanks for any advice!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

I can't help you on the Teradata side of things.

 

But, on the SAS side,

 

If both variables are received as datetimes use:

 

intck('DTWEEKDAY', a.OPEN_DATE, b.DSCHRG_DT)

 

if a.OPEN_DATE is a date and b.DSCHRG_DT is a datetime, use:

 

intck('WEEKDAY', a.OPEN_DATE, datepart(b.DSCHRG_DT))

 

and finally, if one of your variables is a character string, convert it to a SAS date using the PUT() function with the appropriate format for that string.

 

intck('WEEKDAY', PUT(a.OPEN_DATE, date9.), b.DSCHRG_DT)

PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

Does work. If OPEN_DATE and DSCHRG_DT are dates. If one or the other is a datetime or a character string, it won't work.

PG
Jordana_Anthem
Fluorite | Level 6
Thank you, I am working with SAS as a pass through for Teradata databases; is there a way to impose a single date format in upstream code to assure this code will work? Thanks so much!
PGStats
Opal | Level 21

I can't help you on the Teradata side of things.

 

But, on the SAS side,

 

If both variables are received as datetimes use:

 

intck('DTWEEKDAY', a.OPEN_DATE, b.DSCHRG_DT)

 

if a.OPEN_DATE is a date and b.DSCHRG_DT is a datetime, use:

 

intck('WEEKDAY', a.OPEN_DATE, datepart(b.DSCHRG_DT))

 

and finally, if one of your variables is a character string, convert it to a SAS date using the PUT() function with the appropriate format for that string.

 

intck('WEEKDAY', PUT(a.OPEN_DATE, date9.), b.DSCHRG_DT)

PG
Jordana_Anthem
Fluorite | Level 6
This code will work: ,intck('WEEKDAY', a.OPEN_DATE, b.DSCHRG_DT) as Num_BD_Diff
as long as in an upstream query or subquery the Teradata dates are declared something like:
,cast(b.DSCHRG_DT as date) as discharge_date. Thanks!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 3353 views
  • 1 like
  • 2 in conversation