As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.
Here are some tips for How to share your SAS knowledge with your professional network.
Difference between revisions of "Tight Looping with Macro Arrays"
(gardening on the download link and other formatting issues)
m (adjusted category)
|Line 29:||Line 29:|
Latest revision as of 11:57, 27 March 2012
Tight Looping With Macro Arrays
You can apply the power of macro %DO-looping in the tight space of a single statement by using macro arrays. A macro array is a list of macro variables that share the same prefix and a numeric suffix, for example, AA1, AA2, AA3, etc., plus an additional macro variable with a suffix of "N" that contains the length of the array. Two macros:
make it simple to create and use macro arrays.
%ARRAY stores text in a macro array from an explicit list of values or from variables in a data set. Then, wherever you need those text values in your program,
- %DO_OVER loops over the macro array and substitutes the text values wherever you put a "?" in your code phrase.
- %DO_OVER(AA,PHRASE=”?”) generates a list with double-quotation marks around each text string.
- SET %DO_OVER(AA,PHRASE=mylib.?); concatenates a series of data sets.
- RENAME %DO_OVER(AA,PHRASE=?=pre_?); renames a list of variables by adding a prefix.
- %DO_OVER(AA,MACRO=mymacro) repeatedly executes a macro with a series of values.
The code phrase can consist of many statements, and multiple arrays can be defined and looped-over in parallel.
The %ARRAY and %DO_OVER macros turn many time-consuming programming tasks into quick work.
Download a zip file containing the three macros