Not sure why this isn't working, shouldn't I have "end" in the location of the error?
28 proc sql;
29 create table temp as
30 select contract_number, sum(enrollment) as parent_enrol,
31 case when (calculated parent_enrol lt 50000) then 1
32 else case when parent_enrol le 200000 then 2
33 else case when (calculated parent_enrol gt 200000) then 3
34 else 4
35 end as parent_size
__
22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, END, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~,
~=.
ERROR 76-322: Syntax error, statement will be ignored.
36 from D107342.AP15747022_Master
37 group by contract_number;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
38 quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time
EDIT: Too many cases and elses here.
28 proc sql; 29 create table temp as 30 select contract_number, sum(enrollment) as parent_enrol, 31 case when (calculated parent_enrol lt 50000) then 1 32 else case when parent_enrol le 200000 then 2 33 else case when (calculated parent_enrol gt 200000) then 3 34 else 4 35 end as parent_size
Correct syntax
28 proc sql;
29 create table temp as
30 select contract_number, sum(enrollment) as parent_enrol,
31 case when (calculated parent_enrol lt 50000) then 1
32 when parent_enrol le 200000 then 2
33 when (calculated parent_enrol gt 200000) then 3
34 else 4
35 end as parent_size
@Batman wrote:
Not sure why this isn't working, shouldn't I have "end" in the location of the error?
28 proc sql;
29 create table temp as
30 select contract_number, sum(enrollment) as parent_enrol,
31 case when (calculated parent_enrol lt 50000) then 1
32 else case when parent_enrol le 200000 then 2
33 else case when (calculated parent_enrol gt 200000) then 3
34 else 4
35 end as parent_size
__
22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, END, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~,
~=.ERROR 76-322: Syntax error, statement will be ignored.
36 from D107342.AP15747022_Master
37 group by contract_number;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
38 quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time
Still getting an error even with your modification
27 proc sql;
28 create table temp as
29 select contract_number, sum(enrollment) as parent_enrol,
30 case when calculated parent_enrol lt 50000 then 1
31 else when calculated parent_enrol le 200000 then 2
__________
22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, '.', /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, END, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~,
~=.
ERROR 76-322: Syntax error, statement will be ignored.
32 else when calculated parent_enrol gt 200000 then 3
33 else 4
34 end as parent_size
35 from D107342.AP15747022_Master
36 group by contract_number;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
37 quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.