LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext 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 08:11:27 -0700
Reply-To:     karma <dorjetarap@GOOGLEMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         karma <dorjetarap@GOOGLEMAIL.COM>
Organization: http://groups.google.com
Subject:      Re: Calling to a macro with positional parameters' values in a
              SAS data set
Comments: To: sas-l@uga.edu
Content-Type: text/plain; charset=ISO-8859-1

On 9 Jun, 15:33, Jianling Wang <higho...@gmail.com> wrote: > 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

Hi Jianling,

you can use call execute for this problem, to dynamically pass the datastep variables to the your macro.

%macro M (pos1, pos2, pos3); %put &pos1, &pos2, &pos3; %mend M;

data test; input n x y; cards; 1 262 25 216 5 55 12 11 22 11 22 22 ; run;

data _null_; set test; call execute('%M('||n||','||x||','||y||')'); run;

output:

1, 262, 25 216, 5, 55 12, 11, 22 11, 22, 22

If the variables you want to pass are strings and they contain special characters make sure to use a suitable quoting function. Eg:

%macro M (pos1, pos2, pos3); %put &pos1 &pos2 &pos3; %mend M;

data test; input n $1-5 x $6-15 y $17-21 ; cards; this is a test this is a test,this is a test this is ; run;

data _null_; set test; call execute('%M('||n||',%str('||x||'),'||y||')'); run;

output:

this is a test this is a test,this is a test this is

HTH


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