BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
superbug
Quartz | Level 8

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
PGStats
Opal | Level 21

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;

PGStats_0-1627959491398.png

 

PG

View solution in original post

8 REPLIES 8
ballardw
Super User

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.

superbug
Quartz | Level 8

@ballardw 

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?

PGStats
Opal | Level 21

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;

PGStats_0-1627959491398.png

 

PG
superbug
Quartz | Level 8

@PGStats 

Thanks a bunch for your help! 

superbug
Quartz | Level 8

@PGStats 

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!

PGStats
Opal | Level 21

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
superbug
Quartz | Level 8

@PGStats 

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!

superbug
Quartz | Level 8

@ballardw 

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;

sas-innovate-white.png

Special offer for SAS Communities members

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.

 

View the full agenda.

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1762 views
  • 0 likes
  • 3 in conversation