LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (June 2008, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
In-Reply-To:   <fe0d9385-97f9-4a84-b06b-df5c6f1aad8c@k30g2000hse.googlegroups.com>
Content-Type:   text/plain; charset="us-ascii"

Dear SAS-L-ers,

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 these lines:

/* Create Temporary flat file to hold Macro invocations */ filename holdmacs TEMP;

/* Create Macro invocations by reading file with vars */ data _null_; set jianling.threevariables;

file holdmacs;

length outline $100;

outline = '%M(' || positional_1 || ', ' || positional_2 || ', ' || positional_3 || ');';

put outline;

run;

/* Invoke all instances of the Macro from the flatfile */ %INCLUDE holdmacs;

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 Directory" <<http://www2.sas.com/proceedings/sugi30/035-30.pdf>>

Jianling, best of luck in all of your SAS endeavors!

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Michael A. Raithel "The man who wrote the book on performance" E-mail: MichaelRaithel@westat.com

Author: Tuning SAS Applications in the MVS Environment

Author: Tuning SAS Applications in the OS/390 and z/OS Environments, Second Edition http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=58172

Author: The Complete Guide to SAS Indexes

http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=1&pc=60409

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Luck is the residue of design. - Branch Rickey +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Back to: Top of message | Previous page | Main SAS-L page