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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 4 replies
  • 2356 views
  • 1 like
  • 2 in conversation