The following loop ends after one iteration even though Max_V1>5. However the code works perfectly if I use a fraction (say 0.5) instead of a number above 1 (5 in my current code)
%do %until (&Max_V1.) le 5);
a few more lines of code goes here........then ......
PROC SQL NOPRINT;
SELECT VarianceInflation_Max INTO: Max_V1
FROM Sum_stat;
QUIT;
%if &Max_V1. le 5 %then %goto leave;
proc sql;
Select Variable INTO: Drop_Var
from Spdework.varlist where VarianceInflation = (select max(Varia) as MV
from varlist);
quit;
proc sql;
Select Variable INTO: L_F_Vars SEPARATED by ' '
From Varlist
Where Variable <> "&Drop_Var.";
quit;
Thanks for yor reply. I am nit sure why SAS log displays the following message...
SYMBOLGEN: Macro variable MAX_V1 resolves to 49.809566165
MLOGIC(AUTO_VIF): %IF condition %sysevalf(&Max_V1) le 5 is TRUE
MLOGIC(AUTO_VIF): %GOTO LEAVE (label resolves to LEAVE).
MLOGIC(AUTO_VIF): Ending execution.
Did you interrogate the value of SAS variable VarianceInflation_Max in file WORK.Sum_stat? Note your SAS PROC SQL uses this variable to assign the macro variable.
That's the value you see (SAS output format), not necessarily the internal value. Suggest you might use the BEST. format to display the SAS variable - also how is the SAS variable calculated/computed?
> displays the following message...
> SYMBOLGEN: Macro variable MAX_V1 resolves to 49.809566165
> MLOGIC(AUTO_VIF): %IF condition %sysevalf(&Max_V1) le 5 is TRUE
that TRUE above implies a string comparison of %sysevalf(&Max_V1) and the 5.
Perhaps the evaluation of %sysevalf(&Max_V1) needs to be done before the compare in the %do statement
Yes I tried that but it does not work. THe loop works fine if I use a %do %unitl (&Max_V1 lt .9) i.e. I use any number under 1 on the R.H.S. of the inequality sign.
The first %DO statement shown in the original post has incorrect syntax and would generate an error. The %DO %UNTIL(...) logic inside the parentheses must be enclosed in parentheses itself and you must use %SYSEVALF() correctly.
Scott Barry
SBBWorks, Inc.
Suggested Google advanced search argument, this topic / post:
Numeric expressions are evaluated with a %EVAL (which only works with integers). If either side of your expression resolves to a non-integer, and anything with a decimal point including 1. is a non-integer, the comparison becomes alphabetic rather than numeric. Using %SYSEVALF as Scott suggests forces a numeric comparison on non-integers.
Consider the following snippet from my LOG:
[pre]
87 %macro test;
88 %let v=49.5;
89 %if &v lt 5 %then %put &v is less than 5;
90 %if &v gt .5 %then %put &v is GT than .5;
91 %if %sysevalf(&v gt 5) %then %put &v is GT than 5;
92 %mend test;
93 %test
49.5 is less than 5
49.5 is GT than .5
49.5 is GT than 5
[/pre]
Although the second %IF appears to evaluate correctly (numerically) it is actually doing an alphabetic comparison (decimal points sort before numbers alphabetically on my OS - windows).
Only the third expression is actually giving correct numeric results.
The key is to remember that for expressions to be evaluated numerically in the macro language they must be integer or alternatively we take charge with the %SYSEVALF function.
Art