/*expression-by sql*/
/*cretae new variables*/
data emp_sal;
input eid salary sale;
cards;
234 2300 675
245 2400 560
456 8900 567
123 3000 345
236 4000 456
278 5345 523
345 6000 321
111 4500 256
187 4326 390
;
proc sql;
select * ,salary+2000 as newsalary from emp_sal;
quit;
/*conditionalbased*/
proc sql;
select * , case when sale>500 then salary+2000
else salary+1000 end as newsalary from emp_sal;
quit;
proc sql;
select * , salary+ case when sale>500 then 2000
else 1000 end as newsalary from emp_sal;
quit;
proc sql;
select * ,salary+ case when sale>500 then 2000
when sale>350 and sale<500 then 1500
else 1000 end as newsalary from emp_sal;
quit;
proc sql;
select *,case when sale>5000 then 'a+++'
when sale>350 and sale<5000 then 'a++'
else 'a+' end as rating from emp_sal;
quit;
/*create multiple variables for rating*/
proc sql;
select * , salary+ case when
sale>500 then 2000
when sale>350 and sale>500 then 1500
else 1000 end as newsalary ,
case when sale>500 then 'a+++'
when sale>350 and sale<500 then 'a++'
else 'a+' end as rating from emp_sal;
quit;
No comments:
Post a Comment