_______________________________________________________________
=========================================================================
Date: Thu, 20 Feb 2003 16:58:18 -0500
Reply-To: Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject: Re: Using a macro to simulate data
Content-Type: text/plain; charset="iso-8859-1"
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;
%mend pmdata;