BookmarkSubscribeRSS Feed
Sean_OConnor
Fluorite | Level 6

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';
3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Reeza
Super User

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 

http://support.sas.com/kb/32/160.html

Reeza
Super User

And the condition needs to be correct

 

payeinc > 0.5*gross_incone 

sas-innovate-2024.png

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.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2688 views
  • 1 like
  • 3 in conversation