DATA Step, Macro, Functions and more

Confused - Hard coding Logistic Reg Equation

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

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

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

 


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

Re: Confused - Hard coding Logistic Reg Equation

[ Edited ]
Posted in reply to vempatapu
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

View solution in original post


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

Re: Confused - Hard coding Logistic Reg Equation

[ Edited ]
Posted in reply to vempatapu
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
New Contributor
Posts: 4

Re: Confused - Hard coding Logistic Reg Equation

Posted in reply to KurtBremser

thank you bremser thats working buddy.

if your leisure  now .

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

 

Super User
Posts: 7,808

Re: Confused - Hard coding Logistic Reg Equation

Posted in reply to vempatapu

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
New Contributor
Posts: 4

Re: Confused - Hard coding Logistic Reg Equation

Posted in reply to KurtBremser
thank you for answer buddy
New Contributor
Posts: 4

Re: Confused - Hard coding Logistic Reg Equation

Posted in reply to KurtBremser
thank you bremser thats working buddy.
if your leisure now .
please let me know how select and when conditions will work .
Super User
Super User
Posts: 7,970

Re: Confused - Hard coding Logistic Reg Equation

Posted in reply to vempatapu

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 344 views
  • 0 likes
  • 3 in conversation