@ggfggrr wrote:
Dear I understood that it works. However can you please explain how does the following work;
=a.Month+2+88*(mod(a.Month,100)>10)
For example;
I wish to add 2 months to 201711 and it should output 201801.
The reminder for mod(201711,100) is 11.
And 11>10 is TRUE
... and the Boolean value TRUE is interpreted as the numeric value 1 in arithmetic expressions.
Hence, in your example you obtain
=201711+2+88*1
which equals 201801, as desired.
The general idea is to save an IF/THEN statement, IFN function call or (in PROC SQL) a CASE expression by using a Boolean expression in a calculation. In this context the Boolean expression evaluates to 1 for TRUE and 0 for FALSE and this difference can be used to switch between two numeric results. To apply this technique, you only have to develop an arithmetic expression (containing the Boolean expression) whose results switch between the two results you want to obtain depending on the Boolean value. The resulting SAS code is mostly concise, but many people will find the longer code (using IF/THEN etc.) more readable and easier to maintain. So, it's a technique rather for mathematically inclined programmers (and "code poets" ).
... View more