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
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.
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
i want to know what b will get multiplied with ?
the value of P1 as per u .
As i have to do this code migration, i need to understand it
i want to know what b will get multiplied with ?
the value of P1 as per u .
You don't need to build an algorithm for this, this formula can be used as is in SAS.
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.