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

I need help figuring out how to add this SQL code to SAS using proc sql.  I get the error messages that are listed below the code.

AND lh.CreateDate >= CAST(CONVERT(VARCHAR(8),GETDATE()-1,1) as DATETIME)

ERROR: Function VARCHAR could not be located.

ERROR: Function GETDATE could not be located.

ERROR: Expression using subtraction :smileyminus: requires numeric types.

ERROR: Function CONVERT could not be located.

ERROR: Function CAST could not be located.

ERROR: Expression using greater than or equal (>=) has components that are of different data

       types.

ERROR: The following columns were not found in the contributing tables: DATETIME.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

What is the intent of the code. CAST() and GETDATE() are not functions available in SAS.

If you want to get today's date use the TODAY() or DATE() function.

If you want to get the current datetime then use the DATETIME() function.

Which you use will depend on what you want to do and whether the variable CreateDate contains dates or datetime values.

View solution in original post

4 REPLIES 4
SASKiwi
PROC Star

If CreateDate is a SAS Date something like this:

AND lh.CreateDate >= (today() - 1)

PravinMishra
Quartz | Level 8

Hi,

Cast is a teradata function.and If you want to use in porc sql. you can define while creating libname.

libname teradatalib teradata user=user_name pw=pwd cast=yes;

Thanks

Tom
Super User Tom
Super User

What is the intent of the code. CAST() and GETDATE() are not functions available in SAS.

If you want to get today's date use the TODAY() or DATE() function.

If you want to get the current datetime then use the DATETIME() function.

Which you use will depend on what you want to do and whether the variable CreateDate contains dates or datetime values.

mkd
Calcite | Level 5 mkd
Calcite | Level 5

Thanks, with your help I figured it out.

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 10820 views
  • 5 likes
  • 4 in conversation