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 (November 1998, 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 Nov 1998 21:05:17 +0000
Reply-To:     Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Subject:      Re: Can do this by 'one step' ?
In-Reply-To:  <910626621.201654.0@vm121.akh-wien.ac.at>

In article <910626621.201654.0@vm121.akh-wien.ac.at>, Chenglong Han <hanc@CALIB.COM> writes >Hi All: > >I want to invoke a sas macro, for example, MABC, for multiple times. Can I >do this just by invoking once ? For example, >%MACRO MABC ( VAR); > ....... >%MEND; > >Instead of doing this by >%MABC ( X1); >%MABC (X2); >....... >%MABC (Xn); > >Can I do this by some way like >%MABC (X1-XN); > >Thanks. > >Chenglong Han

Much depends on the nature of the parameters of your %MABC

logically, we should be able to use a macro like %macro repeat( this, often ); %local i; %do i= 1 %to &often; &this %end; %mend repeat;

where the parameter &this will resolve to a macro

but that seems a little bit too exotic

simpler, might be just to build a specific one-off macro

%macro loopMabc( macname=MABC, parmpref=X, often= 2 ); %local i; %do i = 1 %to &often; %&macname( &parmpref&i ) %end ; %mend loopMabc;

which you should be able to apply as

%loopMabc( often=&NN )

so I gave it a try --- the %mabc macro I used is a bit simple, but it proves the method

118 %macro loopMabc( macname=MABC, parmpref=X, often= 2 ); 119 %local i; 120 %do i = 1 %to &often; 121 %&macname( &parmpref&i ) 122 %end ; 123 %mend loopMabc; 124 125 %macro mabc( this ); 126 proc print data=_last_; 127 var &this; 128 run; 129 %mend mabc; 130 131 %let NN=4; 132 133 data stuff; 134 do x=1 to 20; 135 OUTPUT; 136 end; 137 run;

NOTE: The data set WORK.STUFF has 20 observations and 1 variables. NOTE: The DATA statement used 0.05 seconds.

138 proc transpose prefix=x; run;

NOTE: The data set WORK.DATA6 has 1 observations and 21 variables. NOTE: The PROCEDURE TRANSPOSE used 0.0 seconds.

139 140 option mprint; 141 142 %loopMabc( often=&NN ) MPRINT(MABC): PROC PRINT DATA=_LAST_; MPRINT(MABC): VAR X1; MPRINT(MABC): RUN;

NOTE: The PROCEDURE PRINT used 0.0 seconds.

MPRINT(MABC): PROC PRINT DATA=_LAST_; MPRINT(MABC): VAR X2; MPRINT(MABC): RUN;

NOTE: The PROCEDURE PRINT used 0.0 seconds.

MPRINT(MABC): PROC PRINT DATA=_LAST_; MPRINT(MABC): VAR X3; MPRINT(MABC): RUN;

NOTE: The PROCEDURE PRINT used 0.0 seconds.

MPRINT(MABC): PROC PRINT DATA=_LAST_; MPRINT(MABC): VAR X4; MPRINT(MABC): RUN;

NOTE: The PROCEDURE PRINT used 0.0 seconds.

Is that enough of "one step" ?

-- Peter Crawford


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