Solved
New Contributor
Posts: 4

# Confused - Hard coding Logistic Reg Equation

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

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

Accepted Solutions
Solution
‎04-05-2016 08:32 AM
Super User
Posts: 10,211

## Re: Confused - Hard coding Logistic Reg Equation

[ Edited ]
``````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;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

All Replies
Solution
‎04-05-2016 08:32 AM
Super User
Posts: 10,211

## Re: Confused - Hard coding Logistic Reg Equation

[ Edited ]
``````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;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 4

## Re: Confused - Hard coding Logistic Reg Equation

thank you bremser thats working buddy.

please let me know how select and when conditions will work .

Super User
Posts: 10,211

## Re: Confused - Hard coding Logistic Reg Equation

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;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 4

New Contributor
Posts: 4

## Re: Confused - Hard coding Logistic Reg Equation

thank you bremser thats working buddy.
please let me know how select and when conditions will work .
Super User
Posts: 9,599

## Re: Confused - Hard coding Logistic Reg Equation

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;```
🔒 This topic is solved and locked.