Solved
Contributor
Posts: 38

# Generate uniques randoms dates

To generate random date in sas, I use this code

``````data random_date;
mindate='01jan2015'd;
maxdate='30dec2017'd;
range = maxdate-mindate+1;
format mindate maxdate randate date9.;
do i = 1 to 100000;
RanDate = mindate + int(ranuni(12345)*range);
output;
end;
run;``````

But how can I generate uniques randoms dates ?

Accepted Solutions
Solution
‎04-20-2017 11:58 AM
Super User
Posts: 9,599

## Re: Generate uniques randoms dates

That would depend on how many fruit bearing trees you had over those 3 years no?

But good question, can't have 10000 unique dates in that period.

All Replies
Super User
Posts: 9,599

## Re: Generate uniques randoms dates

Well to get rid of duplicates you would do:

```proc sort data=randomdate nodupkey;
by randate;
run;```

However I don't think that is what your after is it?  You want 10000 unique dates of a random nature yes?  If so then just loop over your min/max range, and then sample for the items across this range yes/no 10000 results:

```data want;
do randate='01jan2015'd to '30dec2017'd;
output;
end;
run;
proc surveyselect data=want;
method=srs n=10000 out=SampleSRS;
run;```
Posts: 5,535

## Re: Generate uniques randoms dates

One problem: there are only 1096 unique dates in the three year range.

PG
Solution
‎04-20-2017 11:58 AM
Super User
Posts: 9,599

## Re: Generate uniques randoms dates

That would depend on how many fruit bearing trees you had over those 3 years no?

But good question, can't have 10000 unique dates in that period.

Contributor
Posts: 38

## Re: Generate uniques randoms dates

[ Edited ]

So I have to change the number and also the dates like this

``````mindate='01jan1900'd;
maxdate='30dec2017'd;``````

thanks

☑ This topic is solved.