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 (March 2010, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 30 Mar 2010 07:05:09 -0700
Reply-To:     mlhoward@avalon.net
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Mary <mlhoward@AVALON.NET>
Subject:      Re: How to loop the argument of  a macro
Comments: To: Jinto83 <jinto83@SINA.COM>
Content-Type: text/plain; charset="UTF-8"

My favorite way is to load up the arguments into a dataset, then "pop" them off into macro variables, then append the results from inside the loop to a running total.

data runset; informat temperature 8.; infile cards missover; input temperature; cards; 1975 1988 1930 1999 ; runnum + 1; run;

%macro calculatetemperature;

proc sql noprint; select max(runnum) into :max from runset;

%do i=1 %to &max;

proc sql noprint; select temperature into :temperature from runset where runnum = &i; %put temperature=&temperature;

/* then use &temperature in the code */ /* maybe append do loop results to a running data set */ proc append base=allresults data=results; run; %end; %mend;

data allresults; informat ....; stop; run;

%calculatetemperature;

Note that you can load up your data set with as many arguments as you would like in this approach, and vary the do loop when testing, such as start out with 1 to 1 first. The reason I like it so much is that it is so easy to test, whereas I find call executes very hard to test since the %put statements wind up in different places in the log.

-Mary

--- jinto83@SINA.COM wrote:

From: Jinto83 <jinto83@SINA.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: How to loop the argument of a macro Date: Mon, 29 Mar 2010 01:44:13 -0400

Hi,

How do I run a loop say %calculatetemperature(argument=), on a list of 100 arguments:

1975 1988 1930 1999 ....

So that in essence I invoke the macro 100 times ,each time with a different input argument.

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---


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