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

This is easy but I am struggling with it.

 

Field t1.TrnDt is a date but the following syntax gives an error.  I am try to create a new computed column.  What's wrong with this?

 

 

CASE  WHEN   t1.TrnDt >  "01/01/2011" THEN "Late"  ELSE  "Early"   END

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

SAS requires literal dates in the form of ddMONyy or ddMONyyyy, in quotes and followed by D to indicate date

 

So 

CASE  WHEN   t1.TrnDt >  '01Jan2011'd ....

You can use '1Jan2011'd but I generally use the 01Jan so I know I didn't actually mean 10Jan and just missed a digit.

 

There are similar rules for Time or DATETIME literals.

View solution in original post

5 REPLIES 5
ballardw
Super User

SAS requires literal dates in the form of ddMONyy or ddMONyyyy, in quotes and followed by D to indicate date

 

So 

CASE  WHEN   t1.TrnDt >  '01Jan2011'd ....

You can use '1Jan2011'd but I generally use the 01Jan so I know I didn't actually mean 10Jan and just missed a digit.

 

There are similar rules for Time or DATETIME literals.

PadraigODea
Fluorite | Level 6

Easy when you know how !!  Thanks again.

PadraigODea
Fluorite | Level 6

Aaagh!  I spoke too soon.

 

The following date (cut and pasted from SAS)

 

t1.TrnDt = 12JUN2007:00:00:00.000

 

The above date gives an "After" result to the following calculated field;

CASE WHEN  t1.TrnDt >=  '01Jan2011'd      THEN "After" ELSE  "Before" END

 

But surely 2007 is BEFORE 2011 ???   Why does my case statement fail??

ballardw
Super User

The value 12JUN2007:00:00:00.000 is a DATETIME value. SAS datetimes are counts of seconds and SAS dates are counts of days.

So either use something like "12JUN2007:00:00:00"DT OR compare the datetpart of the value to literal, which would probably be your intention:

 

CASE WHEN  datepart(t1.TrnDt)  >=  '01Jan2011'd      

one of my pet peeves are programmers that call datetime values dates or follow what seems to be a Microslop approach of defaulting things to datetime when you actually want dates.

 

PadraigODea
Fluorite | Level 6
Thanks - That's it. Much appreciated.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 5 replies
  • 19079 views
  • 3 likes
  • 2 in conversation