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 2009, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 5 Nov 2009 10:51:38 -0500
Reply-To:     Jonathan Goldberg <jgoldberg@BIOMEDSYS.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jonathan Goldberg <jgoldberg@BIOMEDSYS.COM>
Subject:      Re: how to establish variable with macro
Comments: To: Murphy Choy <goladin@GMAIL.COM>

Murphy:

The trouble with the macro solution you have been given is that it clutters up the data set with variables that aren't being used.

This can be fixed by a macro-generated drop statement: drop %do i = 2 %to &nvars %by 2; x&i %end; ; /*ends the drop statement*/

However, to answer the question as it was asked, the original solution will work with one change: move the "output" statement need to be moved inside the inner loop, so:

>> %macro a(x,y); >> data b; >> %do i=1 %to &x; >> %do j=1 %to &y %by 2; >> x&j=rannor(254115); OUTPUT; /*new location*/ >> %end; >> output; /*old location, delete this line*/ >> %end; >> run; >> %mend a; >> %a(10,10);

Cheers,

Jonathan

On Thu, 5 Nov 2009 15:12:16 +0000, Murphy Choy <goladin@GMAIL.COM> wrote:

>Hi Nicky, > >This macro is more efficient than the one you have written. Please use this one instead. > > >------Original Message------ >From: Tom Abernathy >Sender: SAS(r) Discussion >To: SAS-L@LISTSERV.UGA.EDU >ReplyTo: Tom Abernathy >Subject: Re: how to establish variable with macro >Sent: Nov 5, 2009 9:37 PM > >Don't use macro logic do what you can do with DATA step logic. >Also use meaningful variable names. I renamed X and Y macro variables >based on how they appear to be used. >This makes it more obvious that half of your Xnn variables will never >be assigned values because of the BY clause on the inner DO loop. > >%macro a(nobs,nvars); > data b; > array x x1-x&nvars; > do i=1 to &nobs; > do j=1 to &nvars by 2; > x(j)=rannor(254115); > end; > output; > end; > run; >%mend a; >%a(10,10); > > >On Nov 5, 3:08 am, nickyli <nickyli0...@gmail.com> wrote: >> >> because of my poor english,someone maybe misunderstood the >> meaning.however,i have solve the problem.here is the procedure: >> %macro a(x,y); >> data b; >> %do i=1 %to &x; >> %do j=1 %to &y %by 2; >> x&j=rannor(254115); >> %end; >> output; >> %end; >> run; >> %mend a; >> %a(10,10); >> we can get different data set by changing macroparameter (x,y)- Hide quoted text - >> >> - Show quoted text - > > >Sent from my BlackBerry Wireless Handheld > >-- >Regards, >Murphy Choy > >Certified Advanced Programmer for SAS V9 >Certified Basic Programmer for SAS V9


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