BookmarkSubscribeRSS Feed
Question
Fluorite | Level 6

Hi all,

 

I have a table that contains customer_id (around 1 Millions) and would like to create some random dates for these customers between 01/01/2015 and 01/01/2017 .

 

Please your help would be much appreciated as it is quite urgent.

 

Thank You very much

3 REPLIES 3
Kurt_Bremser
Super User
%let start=01/01/2015;
%let end=01/01/2017;

data _null_;
start = input("&start",ddmmyy10.);
end = input("&end",ddmmyy10.);
interval = end - start;
call symput('start',put(start,best.));
call symput('interval',put(interval,best.));
run;

data want;
set have;
format newdate ddmmyy10.;
newdate = &start + rand() * &interval;
run;

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the for of a datastep!!  Also post what you want out.

 

Here is an example, the diff between the two dates * by random number added to the base date, gives a date between the two values:

data tmp;
  call streaminit(123);      
  a="01JAN2015"d;
  b="01JAN2017"d;
  test="01JAN2015"d + floor((b-a) * rand("uniform"));
  format a b test date9.;
run;
Question
Fluorite | Level 6
Thank You RW9. It's what I need.

##- Please type your reply above this line. Simple formatting, no
attachments. -##

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
  • 3 replies
  • 8142 views
  • 0 likes
  • 3 in conversation