BookmarkSubscribeRSS Feed
telescopic
Calcite | Level 5
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);
5 REPLIES 5
Peter_C
Rhodochrosite | Level 12
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
Cynthia_sas
SAS Super FREQ
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
Ksharp
Super User
I understand what polingjw want to point out. 🙂


[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
telescopic
Calcite | Level 5
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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 838 views
  • 0 likes
  • 5 in conversation