I am trying to run the following code and I am running into this error:
proc sql;
create table data_new as select *,
case when a is not null then 500
else when b>=60 and c=0 then 400
else when d <6 and Days_Arrears>e then 300
else when d <6 and Days_Arrears>e then 200
else when d <6 and Days_Arrears=e then 100
else when f = 'available' then 50
else f = 'vacant' then 25
else 0 end as Points
from data_old;
quit;
Error:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 proc sql; 74 75 create table data_new as select *, 76 77 case when a is not null then 500 78 79 else when b>=60 and c=0 then 400 ____________ 22 76 ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, '.', /, <, <=, <>, =, >, >=, AND, EQ, EQT, GE, GET, GT, GTT, LE, LET, LT, LTT, NE, NET, OR, ^=, |, ||, ~=. ERROR 76-322: Syntax error, statement will be ignored.
Does that answer you question? -> just remove the multiple "else" to keep one at the very end.
proc sql;
create table data_new as select *,
case when a is not null then 500
when b>=60 and c=0 then 400
when d <6 and Days_Arrears>e then 300
when d <6 and Days_Arrears>e then 200
when d <6 and Days_Arrears=e then 100
when f = 'available' then 50
when f = 'vacant' then 25
else 0 end as Points
from data_old;
quit;
https://www.lexjansen.com/wuss/2011/coders/Papers_Lafler_K_72492.pdf
Hello @sasprogramming,
@ed_sas_member has replied to your post while I was still typing my answer ...
I was wondering why nobody had replied to your post yet, because syntax errors are among the easiest errors to resolve. Here's why: The SAS documentation is really good, so that a comparison of a piece of SAS code and the syntax shown there quickly reveals the difference which constitutes the syntax error.
In your example, use, e.g., "case when" (without quotes) as the search terms and the first link returned will be:
CASE Expression :: SAS® 9.4 SQL Procedure User’s Guide, Fourth Edition
(which is the correct one [assuming SAS version 9.4] because the error occurred in a PROC SQL step, not in FedSQL etc.).
It says:
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.