Hi ,
I'm trying to optimise my codes by introducing if and then into a loop.
Part1, the code work fine and I have the desired values. However Part2 does not work when I put another parameter
Part1
scalar a
IF %a ="BB00" or %a ="BB25" or %a ="BB50" or %a ="BB75" or %a ="BB_25" or %a ="BB_50" or %a ="BB_75" THEN a =1.50
else if %a ="CC00" or %a ="CC25" or %a ="CC50" or %a ="CC75" or %a ="CC_25" or %a ="CC_50" or %a ="CC_75" THEN a = 1.25
else if %a ="DD00" or %a ="DD25" or %a ="DD50" or %a ="DD75" or %a ="DD_25" or %a ="DD_50" or %a ="DD_75" THEN a = 1.00
else if %a ="EE00" or %a ="EE25" or %a ="EE50" or %a ="EE75" or %a ="EE_25" or %a ="EE_50" or %a ="EE_75" THEN a = 1.75
else if %a ="FF00" or %a ="FF25" or %a ="FF50" or %a ="FF75" or %a ="FF_25" or %a ="FF_50" or %a ="FF_75" THEN a = 2.00
endif
endif
endif
endif
endif
!a_0 = 0
!a_25 = 0.25
!a_50 = 0.5
!a_75 = 0.75
!a_100 = a
!a_125 = a
!a_130 = a
!a_140 = a
!a_150 = a
!a_175 = a
!a_200 = a
!e_100 = 1
!e_75 = 1
!e_50 = 1
!e_40 = 1
!e_30 = 1
!e_25 = 1
!e_00 =1
Part2
scalar a
scalar b
IF %a ="BB00" or %a ="BB25" or %a ="BB50" or %a ="BB75" or %a ="BB_25" or %a ="BB_50" or %a ="BB_75" THEN a =1.50 and b=1.50
else if %a ="CC00" or %a ="CC25" or %a ="CC50" or %a ="CC75" or %a ="CC_25" or %a ="CC_50" or %a ="CC_75" THEN a = 1.25
else if %a ="DD00" or %a ="DD25" or %a ="DD50" or %a ="DD75" or %a ="DD_25" or %a ="DD_50" or %a ="DD_75" THEN a = 1.00
else if %a ="EE00" or %a ="EE25" or %a ="EE50" or %a ="EE75" or %a ="EE_25" or %a ="EE_50" or %a ="EE_75" THEN a = 1.75
else if %a ="FF00" or %a ="FF25" or %a ="FF50" or %a ="FF75" or %a ="FF_25" or %a ="FF_50" or %a ="FF_75" THEN a = 2.00
endif
endif
endif
endif
endif
!a_0 = 0
!a_25 = 0.25
!a_50 = 0.5
!a_75 = 0.75
!a_100 = a
!a_125 = a
!a_130 = a
!a_140 = a
!a_150 = b
!a_175 = a
!a_200 = a
!e_100 = 1
!e_75 = 1
!e_50 = 1
!e_40 = 1
!e_30 = 1
!e_25 = 1
!e_00 =1
Help with if and then condition , Is it possible to add and after then
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
-
- EViews Developer
- Posts: 563
- Joined: Thu Apr 25, 2013 7:48 pm
Re: Help with if and then condition , Is it possible to add and after then
Hello,
The problem is the clause "a =1.50 and b=1.50" at the end of the first if statement in Part 2. That expression isn't performing what you think it is; you cannot connect two assignment statements with an "and". Remove the "and" and move the "b=1.50" to its own line, so the code becomes:
The problem is the clause "a =1.50 and b=1.50" at the end of the first if statement in Part 2. That expression isn't performing what you think it is; you cannot connect two assignment statements with an "and". Remove the "and" and move the "b=1.50" to its own line, so the code becomes:
Code: Select all
IF %a ="BB00" or %a ="BB25" or %a ="BB50" or %a ="BB75" or %a ="BB_25" or %a ="BB_50" or %a ="BB_75" THEN a =1.50
b=1.50
else if %a ="CC00" or %a ="CC25" or %a ="CC50" or %a ="CC75" or %a ="CC_25" or %a ="CC_50" or %a ="CC_75" THEN a = 1.25
Re: Help with if and then condition , Is it possible to add and after then
Thanks alots, instead of having 15 loops, I have only one now.
Who is online
Users browsing this forum: No registered users and 57 guests