Hi Everyone,
Would like to check why SAS EG is not recognizing "0" in my formula?
Here's the sample computation:
product: SUM(client1,client2)
product_count: SUM(PURCHASE1,PURCHASE2)
Based on the result of this calculation, I would have to create another tagging:
CASE WHEN t1.product >=3 AND t1.product_count=0THEN 'A'
WHEN t1.product =2 AND t1.product_count=1 THEN 'B'
WHEN t1.product =0 AND t1.product_count=1 THEN 'C'
ELSE 'D'
END
Now my Problem is doesnt recognize the "0" value in product calculation.
Any tips?
Thank you!
What do you mean, "is doesnt recognize the "0" ?
Can you show us some data?
Are you sure that you have values of 0 for Product_count when Product is >= 3?
You can run this code to see if your combination(s) actually have any records.
Proc freq data=yourdataset;
tables product * product_count / list missing;
run;
@Reeza wrote:
You're missing a space between the 0 and THEN, does the log indicate any issues with that?
I tested that and surprisingly enough SAS doesn't complain:
39 Proc sql; 40 create table junk as 41 select *, 42 case when age=13then 'A' 43 else 'B' end as group 44 from sashelp.class 45 ; NOTE: Table WORK.JUNK created, with 19 rows and 6 columns. 46 quit;
Result is A for age 13 and B otherwise in the output data. So the code parser is a bit better than expected. Possibly because of the "variables can't start with digits" rules. However because the "then" starts with T the same isn't true with Character variables:
47 Proc sql;
48 create table junk as
49 select *,
50 case when name='Alfred'then 'A'
ERROR: Invalid date/time/datetime constant 'Alfred't.
50 case when name='Alfred'then 'A'
---
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>,
=, >, >=, AND, EQ, EQT, GE, GET, GT, GTT, LE, LET, LT, LTT, NE, NET, NOT, OR, THEN,
^, ^=, |, ||, ~, ~=.
50 case when name='Alfred'then 'A'
---
202
ERROR 202-322: The option or parameter is not recognized and will be ignored.
51 else 'B' end as group
52 from sashelp.class
53 ;
54 quit
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.