Folks,
I would like to create a condtional variable such that if PAYE income is greater than or equal to 50% of gross income then employee = Y if not employee = N
Initially I wanted something as, but the following code doesn't work. Could anyone recommend anything to me, please?
if payeinc>=50% grossinc then employee='Y'; else employee ='N';
For binary choices such as these, your easiest method is either ifn() to return a numeric value or ifc() to return a character. They both have the form:
<variable>=ifn(<condition>,<result positive value>,<result negative value>);
So in your case you can say:
employee=ifc(payinc >= 50,'Y','N');
Note that in the above I am guessing that payinc is numeric (as that would make most sense), if its character - and why are you storing numbers in character fields - then you need to input it first.
Are you using Query builder? If so, try a computed calculation and choose recode to use the GUI to create the code.
Or use an advanced expression and a CASE statement.
SAS note: How to apply if/then logic in SAS EG
And the condition needs to be correct
payeinc > 0.5*gross_incone
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.