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

I'd like to randomly generate random "year based decimal date" based on the year of birth known?

 

Data: unique personal identifier(id), age in months at the time of measurement, year of birth (dob) and BMI (kg/m2) in my data.

 

Your help is appreciated.

 

data today;
input id age_at_msmt_month dob bmi;
cards;
55 12.0 2002 17.1
55 19.4 2002 15.6
55 31.7 2002 17.1
55 45.5 2002 16.8
55 52.3 2002 17.1
21 10.9 2005 16.5
21 19.2 2005 16.6
21 24.5 2005 15.4
11 8.28 2010 16.3
;

data want;
input id age_at_msmt_month dob bmi dob_decimal;
cards;
55 12.0 2002 17.1 2002.36
55 19.4 2002 15.6 2002.36
55 31.7 2002 17.1 2002.36
55 45.5 2002 16.8 2002.36
55 52.3 2002 17.1 2002.36
21 10.9 2005 16.5 2005.89
21 19.2 2005 16.6 2005.89
21 24.5 2005 15.4 2005.89
11 8.28 2010 16.3 2010.12
;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

If the decimal portion is the random part. 

 

data want;
set today;
by id ;
retain rand;
if first.id then do;
rand =round( ceil( rand('uniform')*100)/100, 0.01);
end;

dob_rand = dob+rand;
run;

View solution in original post

4 REPLIES 4
Reeza
Super User

If the decimal portion is the random part. 

 

data want;
set today;
by id ;
retain rand;
if first.id then do;
rand =round( ceil( rand('uniform')*100)/100, 0.01);
end;

dob_rand = dob+rand;
run;
Cruise
Ammonite | Level 13

Reeza, can you help translate the code to R?

Reeza
Super User

If you have age in months at measurement and have the time of measurement you can get closer with the birth date. 

If you're working with other things, there are standards on how to age a population - you typically age half as of July 1st and half after it's a common concept in demography.  

Cruise
Ammonite | Level 13
I thought about this. However, date of measurement is not given 😞

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 695 views
  • 1 like
  • 2 in conversation