BookmarkSubscribeRSS Feed
mrdlau
Obsidian | Level 7

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
2 REPLIES 2
LinusH
Tourmaline | Level 20

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).

Data never sleeps
PGStats
Opal | Level 21

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;
PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2105 views
  • 2 likes
  • 3 in conversation