Hi:
If you're using SQL code, then your CASE statement needs an "AS" to create the "new" column. In the example below, NEWVAR is a character variable that is created based on the CASE condition that an observation meets.
cynthia
proc sql;
create table work.newclass as
select a.Name,
a.Sex,
a.Age,
(case
when a.sex = 'F' and a.age lt 13 then 'One'
when a.sex = 'F' and a.age ge 13 then 'Two'
when a.sex = 'M' and a.age lt 14 then 'Three'
when a.sex = 'M' and a.age ge 14 then 'Four'
else 'None'
end) as newvar
from sashelp.class as a;
quit;
proc print data=newclass;
title 'SQL CASE Example ';
run;
Hi:
If you're using SQL code, then your CASE statement needs an "AS" to create the "new" column. In the example below, NEWVAR is a character variable that is created based on the CASE condition that an observation meets.
cynthia
proc sql;
create table work.newclass as
select a.Name,
a.Sex,
a.Age,
(case
when a.sex = 'F' and a.age lt 13 then 'One'
when a.sex = 'F' and a.age ge 13 then 'Two'
when a.sex = 'M' and a.age lt 14 then 'Three'
when a.sex = 'M' and a.age ge 14 then 'Four'
else 'None'
end) as newvar
from sashelp.class as a;
quit;
proc print data=newclass;
title 'SQL CASE Example ';
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.