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 (May 2001, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 10 May 2001 11:44:43 -0400
Reply-To:     "Brittain, James" <zqr0@CDC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Brittain, James" <zqr0@CDC.GOV>
Subject:      Re: Macro question
Comments: To: "SAS List Serve (E-mail)" <SAS-L@UGA.CC.UGA.EDU>
Content-Type: multipart/alternative;

Basically all you have to do is surround the code that you want to repeat with %MACRO and %MEND and then call it multiple times. Here is the syntax

%MACRO _your_macro_name_ (var1, var2, var3) ; *** VAR1-VAR3 ARE MACRO VARIABLE JUST LIKE IF YOU USE A %LET *** ;

*** YOUR CODE TO BE REPEATED HERE *** ;

*** THE MACRO VARIABLES THAT ARE TO BE SUBSTITUTED MUST BE PREFIXED WITH & *** ;

%MEND _your_macro_name_ ;

%_YOUR_MACRO_NAME_ (parameters to be set)

%_YOUR_MACRO_NAME_ (parameters to be set with second values)

Here is an example with your code:

%MACRO dothis (ds, y1, y2, y3, prefix) ;

data &ds ;

set d1 (keep= var a b c d &y1 &y2 &y3) ;

run ;

proc transpose data=&ds out=&ds name=time prefix=&prefix;

var &y1 &y2 &y3;

by a b c d;

run;

%MEND dothis ;

%DOTHIS (ds=one , y1=y1 , y2=y2 , y3=y3 , prefix=y )

%DOTHIS (ds=two , y1=a1 , y2=a2 , y3=a3 , prefix=a )

%DOTHIS (ds=three , y1=b1 , y2=b2 , y3=b3 , prefix=b )

Hope this gets you started,

Jim

-----Original Message----- From: Eishi Adachi [mailto:eishi13@HOTMAIL.COM] Sent: Thursday, May 10, 2001 11:12 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Macro question

Hi everybody,

I have a question about macro.

I repeat the same proc about 30 times to transfer multivariate to univariate dataset.

I believe macro can make this simpler, but I am not really familiar with macro. The program which I have made is as follows;

data one;

set d1;

keep var a b c d y1 y2 y3;

proc transpose data=one out=one name=time prefix=y;

var y1 y2 y3;

by a b c d;

run;

*/ The program repeats this two steps about 30 times. Then merge all of them at end. Only y1 y2 y3, prefix, and data name change. Other variables are same in all procs.

_____

Get your FREE download of MSN Explorer at http://explorer.msn.com <http://explorer.msn.com>


[text/html]


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