BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SanjuKumari
Calcite | Level 5

I want to evaluate an expression in SAS . Can some one help me understand the meaning of this expression and write a short algo for this expression:

a= b*(c<=i<=d) +1

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @SanjuKumari 

 

It means that the value of variable b is multiplied with the value of the logical expression in the parentheses, and then 1 is added to the result.

 

The logical expression c<=i<=d returns 1, if the value of variable i is within the interval c-d, or otherwise 0. So when variable b is multiplied with the the logical expression, the result is either b or 0.

 

Then you add 1 to the result, which means that variable a is assigned the value b+1 or 1 depending on whether variable i is within the interval c-d or not.

 

 

View solution in original post

7 REPLIES 7
Reeza
Super User

Use the Order of Operations rule of basic mathematics and break it apart.

BEDMAS

 

*B = Brackets;
p1 = c<=i<=d;
*Exponents -none;
*Division and multiplication in the order they appear;
p2 = b*p1;
*Addition and subtraction in the order they appear;
p3 = p2 + 1;

*original formula; A = b*(c<=i<=d) + 1;
*check the difference; diff = p3 - A;

What do you mean by "write a short algo for this expression"?


@SanjuKumari wrote:

I want to evaluate an expression in SAS . Can some one help me understand the meaning of this expression and write a short algo for this expression:

a= b*(c<=i<=d) +1


 

SanjuKumari
Calcite | Level 5

i want to know what b will get multiplied with ?
the value of P1 as per u .

SanjuKumari
Calcite | Level 5

As i have to do this code migration, i need to understand it 

SanjuKumari
Calcite | Level 5

i want to know what b will get multiplied with ?
the value of P1 as per u .

Reeza
Super User
Run the code and test it.
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @SanjuKumari 

 

It means that the value of variable b is multiplied with the value of the logical expression in the parentheses, and then 1 is added to the result.

 

The logical expression c<=i<=d returns 1, if the value of variable i is within the interval c-d, or otherwise 0. So when variable b is multiplied with the the logical expression, the result is either b or 0.

 

Then you add 1 to the result, which means that variable a is assigned the value b+1 or 1 depending on whether variable i is within the interval c-d or not.

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1445 views
  • 0 likes
  • 4 in conversation