Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do .... Until

Status
Not open for further replies.

riskassure

Programmer
May 6, 2005
33
US
In SAS Programming, is there such a syntax

Do.... Until ?

In my example, I want to run a SAS macro repeatedly until the value in a certain table is equal to 0. How would I go about doing that?

Thanks in advance,

Chi
 
Check out
do a search on "until".
Make sure you read carefully the sections entitled "Details" and "Comparisons". Do Until will always execute once, so if the first iteration has a value of 0, it'll execute once then move on. You may want to use Do While(value NE 0) instead.

You can also use %DO %UNTIL in a macro step which may suit you better, depending on the source of your counter.
Enjoy.
 
Thanks ChrisW75!

I got most of it now, using a second macro, which includes %DO %WHILE to run my first macro repeatedly, depending on the counter. However, I am having some problems with this counter, because it's running on an infinite loop.

What I want is to use a %let counter = n somewhere. The n will be the value in a table that is generated as a result of the first macro. So, everytime this first macro is re-run, the table will be generated with a "smaller" n, etc.... Then, the second macro will look at this counter and decide if it should continue or not.

Do you know how this can be achieved?

Thanks in advance!

CW
 
Sorry, no idea what you are trying to do. Let me know what you actually need at the end of the process (and what you have at the start) and I'll have a go.
Cheers.
 
I think I may have figured this out. I was trying to pass a value found in a table to a variable that will be used as a counter in a do... while.... statement. However, this value changes everytime I run a macro. Everytime i run the macro the value decreases, until it reaches 0, and then the do... while... loop stops.

So, in my macro, I have

%macro abc;
blah blah blah... and something is done to Table xyz containing the value I want to use as a counter.
data xyz;
call symput("counter", n);
run;
blah blah blah...
%mend abc;

where counter is the name of my variable and n is the field in Table xyz containing the value I want to use for my counter.

Then, i have another macro that keeps running macro abc until counter = 0:

%macro efg;
%do %while (&counter ne 0);
%abc;
%end;
%mend efg;

Finally, my original code will simply run the macro efg to finish the job:

blah blah blah....
%efg;
blah blah blah....

I don't know if this is the most efficient way. But so far, it seems to work.

Thanks for you help though.

CW
 
Sounds like a pretty smooth method. Can't see an immediate way of making it simpler. Good job!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top