The basic syntax is:
CASE value
WHEN condition THEN result
WHEN condition THEN result
ELSE result
END
In the code below I am just assigning a 1 or a 0 to a column/variable named bool_tf.
Using the CASE expression is pretty straightforward and is another great way to use SQL to get more coding done in fewer steps.
data myData;
input answer $;
datalines;
true
false
true
true
false
false
true
;
proc sql;
create table a as
select answer,
case substr(answer,1,1)
when 't' then 1
when 'f' then 0
end as bool_tf
from myData;
quit;
Very helpful. I do tend to do that sort of thing in the data step not being much of an SQL person myself.
ReplyDeleteSassy Grrrl