Asked • 04/22/19

For in loop equivalent in SAS 9.3?

I'm searching for a while an equivalent of the ***for in* loop** (like in [Python][1] or in R) in SAS 9.3 macro language. The [DO loop][2] seem's to be the solution but did't work exactly as I want. I founded a way to do it in a data step with a *DO loop* but it don't work with the macro language. For example, in a data step, this code is working : DATA _NULL_; DO i = 1,3,5,9; PUT i; END; RUN; And then the log prompt as expected : 1 3 5 9 When I try to do the same with an *%DO* loop in a Macro, I have an error. %MACRO test(); %DO i = 1,2,4,9 ; %PUT i = &i; %END; %MEND; %test(); The log promp these messages : ERROR: Expected %TO not found in %DO statement. ERROR: A dummy macro will be compiled I'm quite new in SAS and stackoverflow so I hope my question is no too stupid. It's so simple to do this in Python and R then it must have a simple way to do it in SAS. Thank's for help - J. Muller [1]: http://docs.python.org/2/tutorial/controlflow.html#for-statements [2]: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201276.htm

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.