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

Hi I need to create 1000 samples for simulation study. Does any one know how to create a random sample with seeds of time + minute + second ? Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
6 REPLIES 6
PGStats
Opal | Level 21

Can you explain further what you mean by "with seeds of time + minute + second"?

 

If you want the pseudo random number seed to be based on the computer clock you can 1) omit to set a seed or 2) set the seed to a negative number.

PG
HappySASUE
Quartz | Level 8

Sure. 

I need to run 1000 times, however with the current code, they all have the same seed = 12345.  I want to create a macro variable which change every time I pull the sample.  One idea is to set the seed macro variable as the time we create the samples. 

for example for the first iteration: if time is 10am 1 minute 1 second   then %let seed = 100101; second iteration seed become   100111 if each simulation takes 10 seconds.  I remember SAS has a function of current time...system....I forget. It create a macro variable of the current time. 

Thanks 

 

%macro uniform(datain =, dataout =, size = );
/*pulling a random sample from original data*/
data &dataout. (drop=obsleft sampsize);
sampsize= &size.;
obsleft=totobs;
do while(sampsize>0);
pickit+1;
if ranuni(12345)<sampsize/obsleft then do;
set &datain. point=pickit
nobs=totobs;
output;
sampsize=sampsize-1;
end;
obsleft=obsleft-1;
end;
stop;
run;

%mend uniform;

PGStats
Opal | Level 21

If datain is always the same, you should use proc surveyselect with option reps=1000.

 

To get a different seed on every iteration, just omit setting the seed yourself. SAS will use the system clock by default.

PG
HappySASUE
Quartz | Level 8

I see.. How about "call streaminit(321)"? Does it use seed 321 for 1000 iterations?   

PGStats
Opal | Level 21

That would reset the seed to 321 at every execution of the datastep.

PG

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 6 replies
  • 1869 views
  • 2 likes
  • 2 in conversation