BookmarkSubscribeRSS Feed
Calcite | Level 5

How can this  EXCEL statement be written in SAS

Excel version:


in Other words, if A<=X and B is blank then  then variable value =1 OR if A<=X and B<1 then variable value =1 else variable value=c

I've used a SAS statement like this:

data want

let value $10:

iF A is  le  X  and B =''  then value= ‘1’:

if A  is le X and B lt A  then values='1':

else value=0

these statements do not bring up correct results. How do use the OR statement correctly here? I think the error is in the implementation of OR.

Opal | Level 21

With SAS, TRUE is 1 and FALSE is 0, so your expression can be written:

value = A<=X and (missing(B) or B<A);


Super User

That doesn't seem like valid SAS code, I think you missed an else for one and a typo, value vs values.

Is this closer:

IF A  le  X  and B =''  then value= 1;

ELSE if A le X and B lt A  then value=1;

else value=0;

Super User

What do you want to do if A is missing? Missing values are always less than anything else and you want to make sure you are getting expected results. If you don't want to assign 1 when A is missing you need to address that.

Calcite | Level 5

What about this:

IF A ne. and A  le  X  and B =.  then value= 1;

ELSE if A ne. and A le X and B lt A  then value=1;

else value=0;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 4 in conversation