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

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
PGStats
Opal | Level 21

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

PG
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

John4
Obsidian | Level 7

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

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

thanks

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2551 views
  • 9 likes
  • 3 in conversation