BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SR79
Fluorite | Level 6

Hi, 

I am trying to simulate a dataset for 100 subjects over the course of 10 days such that the variable y with normal distribution is repeating the same value within each subject per each day.

 

I have the following:

 

data A;

call streaminit(1);

do subject =1 to 100;

 do t = 1 to 10;

y=rand('normal',1,2);

output;

label t='Day';

end;

end;

 run;

 

which produces:

 

subject  day  y

1             1    1.03

1             2    3.02

....

2             1    1.45

2             2    0.39

...

etc.

 

I want this structure: 

 

subject  day  y

1             1    1.03

1             2    1.03

....

2             1    1.45

2             2    1.45

...

etc.

 

Any help is appreciated. 

 

Thank you! 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

So you want a normal distribution accross subjects, but no variation at all within subject, right?  

 

If so, then modify your program by taking the RAND function outside of the inner loop, and put it in the outer loop:

 

data A;
  call streaminit(1);
  do subject =1 to 100;
    y=rand('normal',1,2);
    do t = 1 to 10;
      output;
    end;
  end;
  label t='Day';
run;

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

2 REPLIES 2
mkeintz
PROC Star

So you want a normal distribution accross subjects, but no variation at all within subject, right?  

 

If so, then modify your program by taking the RAND function outside of the inner loop, and put it in the outer loop:

 

data A;
  call streaminit(1);
  do subject =1 to 100;
    y=rand('normal',1,2);
    do t = 1 to 10;
      output;
    end;
  end;
  label t='Day';
run;

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
SR79
Fluorite | Level 6
Perfect thanks!!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2 replies
  • 1448 views
  • 2 likes
  • 2 in conversation