Date: Fri, 9 Jun 2006 21:56:54 -0400
Reply-To: "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject: Re: Simulated Data
I think the requirements here are simple enough to allow it all to be done
in one DATA step. Try:
data simulated(keep = id visit label number);
array grade(4);
do id = 1 to 10;
do visit = 1 to 20;
do i = 1 to 4;
grade(i) = 0;
end;
sum = min(20,floor(21*ranuni(123) ) );
if sum>0 then do i = 1 to sum;
grade(rantbl(123,0.35,0.35,0.25,0.05) ) + 1;
end;
label = 'sum ';
number = sum;
output;
do i = 1 to 4;
label = 'grade'||put(i,2.);
number = grade(i);
output;
end;
end;
end;
run;
On Fri, 9 Jun 2006 15:35:11 -0400, data _null_; <datanull@GMAIL.COM> wrote:
>I think a little PROC PLAN for SUM and then the RANTBL random number
>function for tox grade. Something like this....
>
>proc format;
> value grade
> 1 = 'Grade 1'
> 2 = 'Grade 2'
> 3 = 'Grade 3'
> 4 = 'Grade 4'
> ;
> run;
>proc plan seed=112358;
> factors
> id = 2 ordered
> visit = 4 ordered
> sum = 1 of 20 random / noprint;
> output out=work.plan;
> run;
>data work.toxgrade;
> set work.plan;
> do i = 1 to sum;
> grade = rantbl(112358,.4,.4,.15,.05);
> output;
> end;
> run;
>proc summary data=work.toxgrade completetypes nway;
> class id visit;
> class grade / preloadfmt;
> format grade grade.;
> output out=work.summary(drop=_type_ rename=_freq_=nEvents);
> run;
>proc summary data=work.summary;
> by id visit;
> class grade;
> output out=work.summary(drop=_type_ _freq_) sum(nEvents)=;
> run;
>proc print;
> run;
>
>
>
>On 6/9/06, Frank <deps_bear@yahoo.com> wrote:
>> Hello,
>>
>> I need to simulate data that looks like the following:
>>
>> id visit label number of events
>>
>> 1 1 sum 7
>> 1 1 grade 1 4
>> 1 1 grade 2 2
>> 1 1 grade 3 0
>> 1 1 grade 4 1
>>
>> 1 2 sum 9
>> 1 2 grade 1 5
>> 1 2 grade 2 3
>> 1 2 grade 3 1
>> 1 2 grade 4 0
>>
>> The record 'sum' is the sum total of grade 1-4.
>>
>> What I need to do is first randomly generate the value for 'sum', which
>> is an integer between 0-20. Then, randomly generate values for grade
>> 1-4 such that they add up to 'sum'. The issue though is that the
>> randomly generated values for grade 1-4 needs to be skewed such that
>> grade 1-2 are most common and grade 3 a little less and grade 4 events
>> are remote.
>>
>> Appreciate any ideas.
>>
>> f
>>
|