BookmarkSubscribeRSS Feed
Oscarboots
Quartz | Level 8

Hi Forum, I'm out of ideas on this one. I've tried everything I can find but I'm still getting the error as shown on the attached file ... What can I do to add a new column with various conditions using the expression builder? Thanks

case_Expr_Error.gif


case_Expr_Error.gif
6 REPLIES 6
Reeza
Super User

The word Source shouldn't be in quotes AFAIK

Oscarboots
Quartz | Level 8

Thanks Reeza, but I've tried it with, without you name it...

Reeza
Super User

Couple of things

1. In SAS you refer to dates as '01Mar2009'd instead of 2009-03-01

2. <> is not a valid operator in SAS, it gets interpreted as max, when you probably mean NE, replace it with NE

3. Remove the as "Source" from the code. Notice the bracket after the calculation and the "as calculation" SAS is automatically naming it calculation.

I'm not sure how you're creating the case statement, it may be more helpful to show a screenshot of that.

Hope some of the above helpful.

Oscarboots
Quartz | Level 8

Thanks Reeza,

Now my script is;

CASE      WHEN t1.Date_Created < '01Mar2009'd THEN 'Infield Sales'


               WHEN t1.SalesRepID IS NOT NULL THEN 'Infield sales'


               WHEN t1.CreatedByUserID = 1 AND t1.Date_Created >= '01Mar2009d' THEN 'Online'


               WHEN t1.CreatedByUserID NE 1 THEN 'CallCentre'


ELSE 'Other'


            END

The only error I'm getting is the '<' comparison is on different data types.

I've converted the Original 'Date Time' format to 'DDMMYYN8' so it seems I now have an issue with the date Formats?

Thanks for your help so far Reeza, I think you've nearly got it !

Reeza
Super User

If your original variable in the database is date time you'll need to convert it to a date variable first or wrap all the date_created variables in the datepart function to get just the date portion. Datepart(t1.date_created)

Oscarboots
Quartz | Level 8

Thanks Reeza, I had done the DATEPART bit but then saw that I had written the second date with the apostrophe after the 'd' instead of in front of it.

Now it works fine. Thanks heaps :  >

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