Posted By

rkoopmann on 07/16/09


Tagged

date random function doloop


Versions (?)

random dates


 / Published in: SAS
 

URL: http://quatch.koopmann.us/2009/07/random-dates.html

this is in response to this sas discussion forum thread.

assuming you know the min and max of allowable dates (01jan2005 - 30jun2009, for example), you can use random functions. you don't need to find the number of days in a given month/year, SAS just knows.

a simple min/max check shows the date limits were respected.

  1. data randates;
  2. mindate='01jan2005'd;
  3. maxdate='30jun2009'd;
  4. range = maxdate-mindate+1;
  5. format mindate maxdate randate date9.;
  6. do i = 1 to 10000;
  7. RanDate = mindate + int(ranuni(12345)*range);
  8. output;
  9. end;
  10. run;
  11.  
  12. /* check range */
  13. proc sql;
  14. select distinct
  15. min(randate) format=date9.
  16. , max(randate) format=date9.
  17. from randates;
  18. quit;
  19.  
  20. /* OUTPUT
  21. --------------------
  22. 01JAN2005 30JUN2009
  23. */

Report this snippet  

You need to login to post a comment.