I need to Use SAS random number generation functions `RAND()` and a `DO....END loop` to create 100 obs in variable named X then I want to use another DO loop of 500 rounds to generate a total of 500 samples, each with 100 obs. a sample is basically sampling from a standard normal distribution.
I tried the following code but it does not give me what I need:
data A; call streaminit(123); /* set random number seed */ do i = 1 to 100; X = rand("Normal"); /* random number generator */ output; end; do r = 1 to 500 ; if i then X = rand("Normal"); output; end; run;
Any input will be greatly appreciated.
Do I understand you correctly that you want 50,000 records with random X where the first 100 have I=1, the next 100 have I=2, and so on till the last 100 with I=500? If so, you need to nest the DO loops, like so:
data want ;
call streaminit(123) ;
do I = 1 to 500 ;
do _n_ = 1 to 100 ;
X = rand ("normal") ;
output ;
end ;
end ;
run ;
Kind regards
Paul D.
Do I understand you correctly that you want 50,000 records with random X where the first 100 have I=1, the next 100 have I=2, and so on till the last 100 with I=500? If so, you need to nest the DO loops, like so:
data want ;
call streaminit(123) ;
do I = 1 to 500 ;
do _n_ = 1 to 100 ;
X = rand ("normal") ;
output ;
end ;
end ;
run ;
Kind regards
Paul D.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: