i have doubt in writting code logic
scenario is i have data set of employees with different job codes of total 500 observation in that task as follows
/**************Task******************/
*Take libref.employees as input
*Calculate bonus as 10% of salary for job code FLTAT1 and
write to output datset FL1
*Calculate bonus as 15% of salary for job code FLTAT2
and write to output datset FL2
*Calculate bonus as 20% of salary for job code FLTAT3 and
write to output datset FL3
*For rest all calculate bonus as 25% of salary and
write to output datset rest;
using conditions
im getting the output set upto fl3 but im not getting logic for Rest output dataset .
please help me in that task
data fl1 fl2 fl3 rest;
set libref.employees;
select (jobcode);
when ('FLTAT1') do;
bonus = salary * .1;
output fl1;
end;
when ('FLTAT2') do;
bonus = salary * .15;
output fl2;
end;
when ('FLTAT3') do;
bonus = salary * .2;
output fl3;
end;
otherwise do;
bonus = salary * .25;
output rest;
end;
end;
run;
data fl1 fl2 fl3 rest;
set libref.employees;
select (jobcode);
when ('FLTAT1') do;
bonus = salary * .1;
output fl1;
end;
when ('FLTAT2') do;
bonus = salary * .15;
output fl2;
end;
when ('FLTAT3') do;
bonus = salary * .2;
output fl3;
end;
otherwise do;
bonus = salary * .25;
output rest;
end;
end;
run;
thank you bremser thats working buddy.
if your leisure now .
please let me know how select and when conditions will work .
The SELECT in a DATA step is the logical equivalent of CASE in PASCAL or SWITCH in C, but it is more versatile than those.
While SWITCH in C does need BREAK to exit a branch, SELECT does this automatically.
Also you can use an empty SELECT () and quite complex conditions for every branch.
select ();
when (sky = 'blue') do; .... end;
when (water = 'wet') do; .... end;
otherwise;
end;
What does your input data look like, post a datastep with some test data. You should be able to do it all in one datastep:
data want; set have; select(job_code); when("FLTAT1") bonus=(salary / 100) * 10; when("FLTAT2") bonus=(salary / 100) * 15; ... otherwise; end; run;
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.
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.