BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

Could you please help me to resolve the following syntax error? I'm trying to do this under expression in SAS DI

 

case when KNKBTY = '1' then TBFR10.AGI
5             when KNKBTY = '2' then QISFR10.AGI
6             when QISFR10.AGI=. then TBFR10.AGI
7             end
8             end
              ___
              22
              76
ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN, 
              CONTAINS, EQ, EQT, EXCEPT, GE, GET, GROUP, GT, GTT, HAVING, IN, INTERSECT, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, 
              NOTIN, OR, ORDER, OUTER, UNION, ^, ^=, |, ||, ~, ~=.  

ERROR 76-322: Syntax error, statement will be ignored.

9             end;
7 REPLIES 7
LinusH
Tourmaline | Level 20
If you use the Join transformation, it comes with a point-and-click interface for case statement. It's not super smooth, but try it out, at least as a way of learning the syntax.
Data never sleeps
Babloo
Rhodochrosite | Level 12
Yes I'm using Join transformation but I'm not sure how to use the point and
click interface to know the syntax.
Reeza
Super User
You read the documentation to understand the syntax.
Patrick
Opal | Level 21

DIS adds the end statement for you so don't have it in your expression. You just need to define the CASE bit in the expression.

 

VenuKadari
SAS Employee

Your CASE statement should be as follows:

 

Your case statement should be something like this:

Select

...
case KNKBTY
when '1' then TBFR10.AGI when '2' then QISFR10.AGI else "something"
end as KNKBTY
.....

In DI Studio, In Expression select "CASE"
In Operand: select column (KNKBTY)
Click on New to enter a condition
Enter your condition in "WHEN Condition", Enter Result in THEN Result

Like other user users are suggesting please refer to doc for more information.

 

Tom
Super User Tom
Super User

Are you trying your own SAS code into SAS/DI ?  If so then sure to use valid syntax.  If you are making a program code file then indentation will make it easier for you to verify you have used valid syntax.

case
  when KNKBTY = '1' then TBFR10.AGI
  when KNKBTY = '2' then QISFR10.AGI
  when QISFR10.AGI=. then TBFR10.AGI
  else .
end

For that to work it needs to be part of a valid SQL statement.  Perhaps you are using it as one of the variables in a SELECT statement?  If so then you need to give the new variable a name. So you full SQL statement might look something like this:

select 
  KNKBTY
, QIDFR10.AGI
, case
    when KNKBTY = '1' then TBFR10.AGI
    when KNKBTY = '2' then QISFR10.AGI
    when QISFR10.AGI=. then TBFR10.AGI
    else .
  end as NEW_VAR
from TBFR10
inner join QISFR10
  on QISFR10.id = TBFR10.id
;

 

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
  • 7 replies
  • 1474 views
  • 0 likes
  • 7 in conversation