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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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