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!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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