BookmarkSubscribeRSS Feed
DB_ECON
Calcite | Level 5
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;



%END;
%leave:
%mend auto_vif;
12 REPLIES 12
RickM
Fluorite | Level 6
do until is evaluated at the end of the loop and do while is evaluated at the top of the loop.
DB_ECON
Calcite | Level 5
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

Scott Barry
SBBWorks, Inc.
DB_ECON
Calcite | Level 5
Yes and it has the same value of 49. Thanks.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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?

Scott Barry
SBBWorks, Inc.
Peter_C
Rhodochrosite | Level 12
> 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
DB_ECON
Calcite | Level 5
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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:

sysevalf documentation site:sas.com
ArtC
Rhodochrosite | Level 12
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.
DB_ECON
Calcite | Level 5
if that is the case, then how does the code work whenI I use a fraction (say .1) on the RHS of the inequality. Thanks for your help.
ArtC
Rhodochrosite | Level 12
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
DB_ECON
Calcite | Level 5
Thanks for your reply. I was able to fix the issue with the sysevalf condition in the appropriate place.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 12 replies
  • 1558 views
  • 0 likes
  • 5 in conversation