Quartz | Level 8

## simulation

I have 1000 person, each of the person answered 150 items. I have mean and sd of response time on each of 150 items. Using those information, I want to simulate response time of those 1000 person on 150 items. How should I do that in SAS?

Thanks for the help!

1 ACCEPTED SOLUTION

Accepted Solutions
Opal | Level 21

## Re: simulation

Small example:

``````data have;
person = "A"; meanlog = -0.1; sdlog = 0.5; output;
person = "B"; meanlog = 0.1; sdlog = 0.7; output;
run;

data want;
call streaminit(9768765);
set have;
array itemTime{5}; /* replace by 150 */
do i = 1 to dim(itemTime);
itemTime{i} = rand("lognormal", meanLog, sdLog);
end;
drop i;
format itemTime: 7.2;
run;

proc print; run;
``````

PG
8 REPLIES 8
Super User

## Re: simulation

What do you mean by "simulate" in this case? You description makes it sound like you already have 1000 respondents actual responses. So what would a simulation gain you?

Or are you trying to generate 1000 other records that aren't from actual people as an exercise?

Do you have the mean and SD in a data set?

Do you have any sort of idea what distribution the original data follows?

The RAND function can create values from many distributions but only a few use mean and/or standard deviation directly as parameters. If the data were normally distributed (or "close") you can generate values using x= Rand('normal',mean,sd); Which might work but you need to have something that holds 150 pairs of values, such as arrays, to access them easily.

Quartz | Level 8

## Re: simulation

I have a dataset contains mean and sd of response time for 150 items. The mean and sd is after lognormal transformation. I am trying to simulate 1000 people's response time on 150 items based on the mean and sd dataset.

I understand the function  x= Rand('normal',mean,sd) you mentioned. I am having difficulty of incorporating 150 means and sd into this function, the arrays as you said. Can you please provide more information/example SAS code?

Opal | Level 21

## Re: simulation

Small example:

``````data have;
person = "A"; meanlog = -0.1; sdlog = 0.5; output;
person = "B"; meanlog = 0.1; sdlog = 0.7; output;
run;

data want;
call streaminit(9768765);
set have;
array itemTime{5}; /* replace by 150 */
do i = 1 to dim(itemTime);
itemTime{i} = rand("lognormal", meanLog, sdLog);
end;
drop i;
format itemTime: 7.2;
run;

proc print; run;
``````

PG
Quartz | Level 8

## Re: simulation

Thanks a bunch for your help!

Quartz | Level 8

## Re: simulation

As to the code you helped, if I want to generated item time for 1000 person on 150 items, how should incorporate the information of 1000 into the code?  Can you please provide more direction? Thanks much!

Opal | Level 21

## Re: simulation

You must create a dataset with variables Person, meanLog and stdLog. I guess that this data could be extracted from the data you already have. I can't be more precise unless I know what your data looks like.

PG
Quartz | Level 8

## Re: simulation

I figured out I must prepare the data as your recommended in order to easily apply the code you helped.

Very much appreciate your help and expertise!

Quartz | Level 8

## Re: simulation

Below is my trial for 1000 people's response time on the first item. I have data contains mu and sigma for 150 items. Could you please direct me how to use array function to incorporate mu and sigma for 150 items into the code below? Many thanks!

``````
%Let person = 1000;
%Let mu = 53.6692552122;
%Let sigma = 0.5671923308;
%Let norm = rand('normal',&mu, &sigma);
data RandomNormal;
do x=1 to &person;
time=&norm;
output;
end;

proc print data=RandomNormal; run;``````
Discussion stats
• 8 replies
• 848 views
• 0 likes
• 3 in conversation