|Date: ||Mon, 9 Jun 2008 11:03:57 -0400|
|Reply-To: ||Michael Raithel <michaelraithel@WESTAT.COM>|
|Sender: ||"SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>|
|From: ||Michael Raithel <michaelraithel@WESTAT.COM>|
|Subject: ||Re: Calling to a macro with positional parameters' values in a
SAS data set|
|Content-Type: ||text/plain; charset="us-ascii"|
Jianling Wang posted the following:
> Hi All,
> I need to run a macro with three positional parameters like this:
> %macro M (positional-1, positional-2, positional-3);
> macro codes here
> %mend M;
> My problem is that I need to run this macro 200 times,
> while the values of the positional parameters were stored in
> a data set of three variables and 200 observations. Is there
> a way to tell SAS to look for the values in the data set
> instead of me manually write 200 lines of code calling to the
> macro M (the only way I know now to accomplish the task)?
> I appreciate your time and attention to this!!
Jianling, that is an interesting question. I like to do this along
/* Create Temporary flat file to hold Macro invocations */
filename holdmacs TEMP;
/* Create Macro invocations by reading file with vars */
length outline $100;
outline = '%M(' || positional_1 || ', ' || positional_2 || ', ' ||
positional_3 || ');';
/* Invoke all instances of the Macro from the flatfile */
You may have to futz around with the spacing (eg. trim/left), commas,
etc. in OUTLINE, but the general methodology should be sound.
This is better illustrated in my SUGI 30 Coders' Corner paper:
Automatically Process a Varying Number Of New Data Files From a "Data
Jianling, best of luck in all of your SAS endeavors!
Michael A. Raithel
"The man who wrote the book on performance"
Author: Tuning SAS Applications in the MVS Environment
Author: Tuning SAS Applications in the OS/390 and z/OS Environments,
Author: The Complete Guide to SAS Indexes
Luck is the residue of design. - Branch Rickey