Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- simulation

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 08-02-2021 04:35 PM
(847 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks much for your reply!

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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks a bunch for your help!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks much for your reply!

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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;
```

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.