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

I know I've used CASE in the past, but for some reason in my current job I'm unable to use a CASE statement as an expression in an Extract.

The expression is as simple as:

CASE

     WHEN sourcecolumn = 'Y' then targetcolumn = 'Yes'

ELSE sourcecolumn

END

I've tried many variations, but none validate. It seems there is a syntax error at the very beginning. When I look at the validation log, it appears as if the code actually says:

WHERE CASE

WHEN...

Where does that WHERE come from? I think it is causing the error. (I have nothing in the WHERE tab of the Extract Transformation)

Also, I recall in the expression field of the target column in the MAPPINGS tab, if I were to right click a CASE option would be available. A co-worker also sees this option. I don't

Is there something off in my job settings preventing the use of a CASE statement in an Extract? How do I get rid of the WHERE? Any other solutions?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

This is a flaw in DI Studio, when validating an expression, it often (not always) puts the expression in a where clause, even if the expression is in a select clause.

In those cases, just ignore the error. You are better off validating by running the transformation instead - if your syntax is valid, it will succeed.

Tip: DI Studio will default output to a view. Temporarily switch to a table - that will reveal any error at once (instead of when reading the view from succeeding transformations).

Data never sleeps

View solution in original post

11 REPLIES 11
stat_sas
Ammonite | Level 13

Try this.

CASE

     WHEN sourcecolumn = 'Y' then  'Yes'

ELSE sourcecolumn

END as targetcolumn

jwhite
Quartz | Level 8

Still getting the error.

Here's the CASE statement in the Expression:

c1.PNG

Here's the error:

c2.PNG

Still, any idea why CASE isn't an option in the expression field?

c3.png

stat_sas
Ammonite | Level 13

Just a small modification in END as statement. Hopefully, this can provide the desired results.

CASE

     WHEN group = 'Y' then  'Yes'

ELSE group

END as group

jwhite
Quartz | Level 8

Made the modification to the CASE statement:

c4.PNG

Still getting the error:

c5.PNG

Like I mentioned, I wonder if it has anything with that WHERE syntax being inserted on line 9. Could it be causing the issue, and where is it coming from?

Loko
Barite | Level 11

Hello,

If I see correctly from your print screen you are trying to use CASE expression in a where clause. Try the following:

proc sql;

select *, CASE

     WHEN sex = 'M' then  'Male'

ELSE sex

END as newsex

from sashelp.class

having newsex='Male' ;

quit;

jwhite
Quartz | Level 8

Well, I'm not trying to use CASE within a WHERE clause. How is this WHERE clause getting generated? Is it by default?

jwhite
Quartz | Level 8

ok, I tried that proc sql statement:

c6.PNG

It appeared to validate, but when I opened the validation log...still an error:

c7.PNG

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Now this is just a guess, but where are you posting that sql code.  I assume from the Data Management section that you are using some kind of graphical interface tool, I would assume that you are trying to put into what equates to a Where Condition window.  So the "where" is the default text, which then takes the text you put in Expression column to try to evaluate rows, so in Loko's example, the case statement has been moved from the conditional part, up to the selection part.  You would need to put the case in another column on your table, not the Expression one.

Sorry, can't be more specific, I avoid all types of graphical interface for these kind's of reason - faster and simpler to write code!

jwhite
Quartz | Level 8

Ha! Great point...I forgot to mention that this is in Data Integration Studio. It is an interface tool.

LinusH
Tourmaline | Level 20

This is a flaw in DI Studio, when validating an expression, it often (not always) puts the expression in a where clause, even if the expression is in a select clause.

In those cases, just ignore the error. You are better off validating by running the transformation instead - if your syntax is valid, it will succeed.

Tip: DI Studio will default output to a view. Temporarily switch to a table - that will reveal any error at once (instead of when reading the view from succeeding transformations).

Data never sleeps
jwhite
Quartz | Level 8

LinusH, thanks!

I just found this out...I ignored the validation error, executed the job, and the Extract ran fine.

Odd, but good to know!

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!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 11 replies
  • 4767 views
  • 0 likes
  • 5 in conversation