DATA Step, Macro, Functions and more

macro with changing argument

Reply
Occasional Contributor
Posts: 15

macro with changing argument

Hi everyone, I am more used to matlab data manipulation and find Sas
synthesis difficult to understand sometimes.

Suppose the macro 'prog_iter' is programmed correctly. It takes a value 'k'
as input. My question is how to use do-loop to let k being different values .
(Eg. for k=0.
01 to 1 by step of 0.01) or any ways.

Thank you in advance
----------------------------------------------------------------------
%prog_iter(k=0);
%prog_iter(k=0.01);
%prog_iter(k=0.02);
Regular Contributor
Posts: 171

Re: macro with changing argument

Posted in reply to telescopic
Valued Guide
Posts: 2,177

Re: macro with changing argument

Posted in reply to telescopic
you may find that you could insert a %DO loop inside the macro where you want to do some looping.
Alternatively you can create a wrapper macro that will derive the value you want to supply and then call your %prog_iter. Something like this untested code:

%macro looping( from_value= 0, to_value= 1, by_val= .01 );
%* but because simple old sas macro iterative %do from/to/by looping expects integers, ...;
%let this val = &from_val ;
%do %while( %sysevalf( &this_val LE &to_val ) ;
%prog_iter( k= &this_val )
%let this_val = %sysevalf( &this_val + &by_val ) ;
%end ;
%mend looping ;
which you could invoke with
%looping( from_value= .01, to_value= .9, by_val= .015 )

but be very careful before extending the use of this %looping to negative &by_val ;-)

peterC
SAS Super FREQ
Posts: 8,868

Re: macro with changing argument

Posted in reply to telescopic
Hi,
This is a good paper that explains the basics of macro processing. It covers what a macro program is and why you can only use %IF and %DO in a macro program (Step 9).
http://www2.sas.com/proceedings/sugi28/056-28.pdf

Of course, you'll need to read the rest of the steps and understand them before you proceed.

cynthia
Super User
Posts: 10,041

Re: macro with changing argument

Posted in reply to telescopic
I understand what polingjw want to point out. Smiley Happy


[pre]


%macro prog_iter(k=);
%put k=&k;
%mend prog_iter;

Data _null_;
do i=0.1 to 1 by 0.1;
call execute('%prog_iter(k='||i||')');
end;
run;
[/pre]

Ksharp
Occasional Contributor
Posts: 15

Re: macro with changing argument

The call execute method is clean and clear. Macro wrapper method is instructive too. Before that, I was even thinking how to let the %pro_iterate(k=) to accept a sas data set as input, which has values 0.01, 0.02,... 0.10 !

Thank all of you.
Ask a Question
Discussion stats
  • 5 replies
  • 137 views
  • 0 likes
  • 5 in conversation