I'm having a problem using the random number function for dates that have missing days.
Does anyone know how to get around assigning non existent days to certain months? As it is, I had to cut the number off at 28 in order not to get errors.
Using the following code:
but had to change it to:
to avoid errors for non-existent days by month.
Assuming you know the month and the year you could use the functions
maxdays = day (end_of_month);
to determine the number of days in the month and then use your random funtion
(The 0 tells SAS to advance the date specified (MDY(DELIV&_I._MONTH,1, DELIV&_I._YEAR) 0 months , the "E" sets that date to the end of the month, day returens the day part of the last date in the month.
assuming you know the min and max of allowable dates (01jan2005 - 30jun2009, for example), you can use random functions.
range = maxdate-mindate+1;
format mindate maxdate randate date9.;
do i = 1 to 10000;
RanDate = mindate + int(ranuni(12345)*range);
using this method, 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
, max(randate) format=date9.