turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- %do %until loop resolves even though condition is ...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-15-2010 09:25 AM

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;

%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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-15-2010 09:34 AM

do until is evaluated at the end of the loop and do while is evaluated at the top of the loop.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-15-2010 09:42 AM

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.

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-15-2010 10:45 AM

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.

Scott Barry

SBBWorks, Inc.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-15-2010 10:59 AM

Yes and it has the same value of 49. Thanks.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-15-2010 11:03 AM

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.

Scott Barry

SBBWorks, Inc.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-15-2010 11:56 AM

> 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

> 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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-15-2010 01:02 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-15-2010 01:43 PM

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

Scott Barry

SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

sysevalf documentation site:sas.com

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-15-2010 01:55 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-15-2010 02:43 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-15-2010 03:09 PM

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

[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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-15-2010 03:26 PM

Thanks for your reply. I was able to fix the issue with the sysevalf condition in the appropriate place.