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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with macro debugging

Status
Not open for further replies.

janelange

Technical User
Jun 12, 2003
45
US
Hi,

I'm writing a macro that needs to use various different random seeds for different invocations of a subroutine, but I only want to enter one as an argument in the main macro.

I have some code, but I'm not sure if it's working.

Here's what the code looks like:



Code:
%macro test1(seed);

%macro test2;
%some_macro(&seed);
%let seed =%eval(&seed+2);
*update random seed to new value for use in next invocation of "test2";
%mend test2;

%test2;
%test2;

%mend test2;

%test1(111);
*this should run "some_macro" with 111 and 113 as seeds;

Is this the right way to do something like this, and if so, is there an output statement to make sure that the seed variable is changing when I want it to?

Thanks!
Jane
 
Rather than using an algorithm to get your random seed, why not use the datetime?

Code:
data _null_;
  seed = datetime();
  call symput('SEED',seed);
run;

Datetime() returns the number of seconds since 01/01/1960. You can scale it down to a more manageable number by subracting from the figure.

To test your macro above, you want to use this:-
Code:
%put seed = &seed;
which will write out the value of seed.

I think you may have overcomplicated you macro above, you shouldn't need 2 nested macro loops (that's what I would call "ugly code").
You can set up do loops in macro code, so you'd probably be better with something more like this format:-
Code:
* set up the macro you want to run multiple times *;
%macro some_macro(var);
  %put &var;
%mend some_macro;


%macro runit();
  %let runs = 4;  * set number of times you want it run *;
  %let count = 0; * initialise counter *;
  %do %until (&count = &runs);
    %let count = %eval(&count + 1);
    %some_macro(&count);  * call macro... *;
  %end;
%mend runit;

%runit;
This is a simplistic example, and just writes out the passed value repeatedly. If you want specific seeds passed in (like your 111 and 113) this is the way to do it.
Enjoy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top