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;
A case in SQL needs only one end.
Read the documentation.
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.
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.
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
;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.