/ 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.
Expand |
Embed | Plain Text
data randates; mindate='01jan2005'd; maxdate='30jun2009'd; range = maxdate-mindate+1; format mindate maxdate randate date9.; do i = 1 to 10000; RanDate = mindate + int(ranuni(12345)*range); output; end; run; /* check range */ proc sql; select distinct min(randate) format=date9. , max(randate) format=date9. from randates; quit; /* OUTPUT -------------------- 01JAN2005 30JUN2009 */
You need to login to post a comment.
