I want to do a loop without having to go into a data step or write a macro. I thought %do would work but it seems like I have to use that within a macro. Are there any alternative to %do or am I stuck defining Macros and then calling them. Basically want to do this without annoyingly having to wrap it in a macro. thanks
%Macro Make_5 ;
%DO I = 1 %TO 5;
%put -------- D&I;
%END;
%Mend Make_5;
You can use conditional macro statements (%IF..%THEN...%ELSE) in open code, without a macro. However, loop iterations for a block of code does require a %macro/%mend block.
Don't overlook the DATA step iteration, which can be used to take an action for every observation in a data set. We often see people going straight to macro when actually a DATA step is more appropriate.
This is a non-issue issue. Just go ahead and use the macro.
%do must be in a macro
The question is what are you attempting to do? All you are doing in the code is writing a message to the log
---D1
---D2
...
I'm guessing you want to do something more than just that, so what do you want to do?
just playing with it now . but thinking more a long the lines of using it along with %IF %THEN %DO.
sth slong the lines of . Trying to learn data driven programming.
%IF &SYSDAY=Friday %THEN %DO;
%do I=1 %to 5;
data d&i;
*some data junk;
run;
%end;
%END;
So ignoring the fact you are missing %MACRO/%MEND statements to define the macro
What you have here is some code to create 5 identical datasets called d1, d2, d3, d4 & d5
It's not the most efficient approach if creating 5 identical datasets is the goal, although it is an approach that will work.
You can use conditional macro statements (%IF..%THEN...%ELSE) in open code, without a macro. However, loop iterations for a block of code does require a %macro/%mend block.
Don't overlook the DATA step iteration, which can be used to take an action for every observation in a data set. We often see people going straight to macro when actually a DATA step is more appropriate.
@thryce85 wrote:
I want to do a loop without having to go into a data step or write a macro.
To do what exactly?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: