Date: Tue, 26 Aug 2003 18:42:21 +0000
Reply-To: sashole@bellsouth.net
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Subject: Re: Simple macro or simulation question
Content-Type: text/plain; format=flowed
Ian,
But indeed...
Kind regards,
=================
Paul M. Dorfman
Jacksonville, FL
=================
>From: Ian Whitlock <WHITLOI1@WESTAT.COM>
>Reply-To: Ian Whitlock <WHITLOI1@WESTAT.COM>
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Re: Simple macro or simulation question
>Date: Tue, 26 Aug 2003 13:45:34 -0400
>
>Paul,
>
>Am I missing something? I don't see why there is any need for an array
>except to complectify the code.
>
>%macro SIM ( dim1=1, dim2=1, repeat=1, seed=0, sim_dsn=SIM, corr_dsn=CORR)
>;
> data &sim_dsn (KEEP = SEQ VAR1 VAR2) ;
> DO SEQ = 1 TO &repeat ;
> do i = 1 to &dim1 ;
> var2 = 0 ;
> do j = 1 to &dim2 - 1 ;
> temp = rannor(&seed) ;
> var2 ++ temp ;
> end ;
> temp = rannor(&seed) ;
> var1 = var2 + temp ;
> output ;
> end ;
> END ;
> run ;
> PROC CORR NOPRINT DATA = &sim_dsn OUT = &corr_dsn
>(WHERE=(_TYPE_='CORR'))
>;
> BY SEQ ;
> VAR VAR1 VAR2 ;
> RUN ;
>%mEnd SIM ;
>
>IanWhitlock@westat.com
>-----Original Message-----
>From: Paul Dorfman [mailto:paul_dorfman@HOTMAIL.COM]
>Sent: Tuesday, August 26, 2003 12:34 PM
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Re: Simple macro or simulation question
>
>
>Peter,
>
>Ya has already given you the right answer. The only reason you may want a
>macro is not repeating the data setp and proc 1000 times, but the
>flexibility of parameterization - if you need one. For example, your array
>dimestions, the number of repetitions, output data sets' names, the seed,
>etc, for example:
>
>%macro SIM ( dim1=1, dim2=1, repeat=1, seed=0, sim_dsn=SIM, corr_dsn=CORR)
>;
> data &sim_dsn (KEEP = SEQ VAR1 VAR2) ;
> array ONE ( &dim1 , &dim2 ) _TEMPORARY_ ;
> DO SEQ = 1 TO &repeat ;
> do i = 1 to &dim1 ;
> do j = 1 to &dim2 ;
> ONE (i, j) = rannor(&seed) ;
> end ;
> end ;
> do i = 1 to &dim1 ;
> var1 = 0 ;
> do j = 1 to &dim2 ;
> var1 ++ one (i, j) ;
> end ;
> var2 = 0 ;
> do j = 1 to &dim2 - 1 ;
> var2 ++ one (i, j) ;
> end ;
> output ;
> end ;
> END ;
> run ;
> PROC CORR NOPRINT DATA = &sim_dsn OUT = &corr_dsn
>(WHERE=(_TYPE_='CORR'))
>;
> BY SEQ ;
> VAR VAR1 VAR2 ;
> RUN ;
>%mEnd SIM ;
>
>%SIM ( dim1=96, dim2=4, repeat=1000 )
>
>Above, I took the liberty to make the array temporary (there is no need
>here
>to pollute the compiler's dymbol table, and in the case the dimensions grow
>in the future, the temporary array will scale much better with respect to
>the computer resources) and to make the computation of VAR1 and VAR2 a bit
>more flexible. You can also add other parms to control other things
>depending on your future needs.
>
>Kind regards,
>=================
>Paul M. Dorfman
>Jacksonville, FL
>=================
>
> >From: Peter Flom <flom@NDRI.ORG>
>
> >I am very new to macros, having only written a couple of very simple
> >things. I'm not even entirely sure a macro is the way to go here.
> >
> >What I would like to do is run the following program (say) 1000 times,
> >saving the correlation between var1 and var2 for each run.
> >
> >Any help appreciated
> >
> >START OF CODE
> >
> ><<<<
> >
> >data today;
> > array ONE (96,4);
> > do i = 1 to 96;
> > do j = 1 to 4;
> > ONE (i, j) = rannor(0);
> > end;
> > end;
> > do i = 1 to 96;
> > var1 = one(i, 1) + one(i, 2) + one (i,3) + one(i,4);
> > var2 = one(i, 1) + one(i, 2) + one (i,3);
> > output;
> > end;
> >run;
> >proc corr data = today;
> > var var1 var2;
> >run;
> >data today;
> > array ONE (96,4);
> > do i = 1 to 96;
> > do j = 1 to 4;
> > ONE (i, j) = rannor(0);
> > end;
> > end;
> > do i = 1 to 96;
> > var1 = one(i, 1) + one(i, 2) + one (i,3) + one(i,4);
> > var2 = one(i, 1) + one(i, 2) + one (i,3);
> > output;
> > end;
> >run;
> >proc corr data = today;
> > var var1 var2;
> >run;
> >
> >
> > >>>>
> >
> >END OF CODE
> >
> >
> >thanks in advance
> >
> >Peter
> >
> >Peter L. Flom, PhD
> >Assistant Director, Statistics and Data Analysis Core
> >Center for Drug Use and HIV Research
> >National Development and Research Institutes
> >71 W. 23rd St
> >www.peterflom.com
> >New York, NY 10010
> >(212) 845-4485 (voice)
> >(917) 438-0894 (fax)
>
>_________________________________________________________________
>Get MSN 8 and help protect your children with advanced parental controls.
>http://join.msn.com/?page=features/parental
_________________________________________________________________
Get MSN 8 and enjoy automatic e-mail virus protection.
http://join.msn.com/?page=features/virus
|