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!
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;
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.
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?
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;
Thanks a bunch for your help!
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!
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.
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!
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;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.