I have a sample proc sql code that wont run.
proc sql;
select
(CASE
WHEN t1.variable = 0 THEN 'No'
ELSE t1.variable end) as ColumnName
FROM TABLE T1;
quit;
Running this gives me an error of:
"Result of WHEN Clause 2 is not the same data type as the preceding results"
Is it because the result wants to be an integer? If so, how do I out put a "NO"?
I tried to put a colon between the 0, but get the following:
Expressing using equals (=) has components of different data types
result of when clause 2 is not the same data type as preceding results
Correct, you cannot mix chars into numerical variables.
You have some options. Either store the result in a char variable (requires put() on the t1.variable).
Or perhaps can live with using 0 or . (Missing) instead of a NO. (Which a format could fix).
If you require "No" for display purposes then a format would do a good job:
proc format;
value no
0 = "No";
run;
proc sql;
select
t1.variable as ColumnName format = no.
FROM T1;
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.