>Filtronic Compound Semiconductors Ltd
=========================================================================
Date: Fri, 21 Feb 2003 07:57:43 -0500
Reply-To: Howard_Schreier@ITA.DOC.GOV
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Howard_Schreier@ITA.DOC.GOV
Subject: Re: Using a macro to simulate data
Ian has identified the essential problem.
A few additional thoughts ...
Putting the global parameters in a one-observation dataset works, but a
generally more convenient technique is to use macrovariables:
%let theta=%sysfunc(rand(beta,2,3));
%let tau=%sysfunc(sqrt(2.25*(1-&theta**2)));
Maybe Ian will explain why the quotation marks come off the first RAND
parameter.
And, by the way, can anybody help me locate the RAND function in the online
doc?
Back to Victor's problem: We don't know all of the requirements, but I'm
wondering if it's necessary to generate separate datasets for the 10
subjects. I generally prefer to stack data together and add a categorical
variable to use in BY-group processing.
In that case, there is no need for a macro; a single DATA step does it:
data tmp(keep=id mu x);
do id = 1 to 10;
mu=0.97+15.87*rand('beta',3,3); **ID-specific mean for PM;
x=0;
do i=1 to 24;
x= mu*(1-&theta) + &theta*x + ( &tau*normal(0) );
if i>20 then output;
end;
end;
run;
On Thu, 20 Feb 2003 16:58:18 -0500, Ian Whitlock <WHITLOI1@WESTAT.COM>
wrote:
>Victor,
>
>It is the same problem, only this time by design it appears that you cannot
>get at the seed! Wow! Watchout for anybody who wants you to rund the code
>again and get the same results.
>
>Here are hints at two possibilities.
>
>%macro pdata;
> %do id=1 %to 10;
> data tmp&id;
> x = sleep ( 2 ) ;
> b23=rand('beta',2,3); put b23=;
> mu&id=0.97+15.87*b23; **ID-specific mean for PM;
> run;
> %end;
>%mend pdata;
>%pdata
>
>
>data w ;
> do i = 1 to 10 ;
> b23=rand('beta',2,3); put b23=;
> output ;
> end ;
>run ;
>
>So, generate all your data in one DATA step and use a WHERE statement to
get
>the right subset.
>
>IanWhitlcok@westat.com
>-----Original Message-----
>From: Victor Gastanaga [mailto:vgastana@UCI.EDU]
>Sent: Thursday, February 20, 2003 3:33 PM
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Using a macro to simulate data
>
>
>I'm generating artificial data for 10 subjects. For each subject I generate
>4 measurements of X, for a total of 40 data points. I randomly determine
the
>mean of X for each subject, and then proceed to generate 4 measurements
>based on each subject-specific mean.
>
>The 4 values of X are generated following an autoregressive process. My
>problem is this: Every time I run the program I find out that two of the 10
>subjects have identical X data (as revelaed by the proc print below). I
>haven't been able to figure out why. Any guidance will be greatly
>appreciated.
>
>This is my code (where the X variable is called PM):
>
>data one; * first create global parameters;
>
> theta=rand('beta',2,3); **AR(1) coeff for PM;
>
> tau=sqrt(2.25*(1-theta**2)); **Std dev for error term in AR(1) for PM;
>
>run;
>
>%macro pmdata;
>
>%do id=1 %to 10;
>
> data tmp&id(keep=mu&id x); set one;
>
> mu&id=0.97+15.87*rand('beta',3,3); **ID-specific mean for PM;
>
> do i=1 to 24;
>
> retain x 0;
>
> x= mu&id*(1-theta) + theta*x + ( tau*normal(0) );
>
> if i>20 then output;
>
> end;
>
> run;
>
>proc print data=tmp&id; run;
>
>%end;
|