## Randomly generate decimal year. Translate SAS code to R?

Solved
Super Contributor
Posts: 374

# Randomly generate decimal year. Translate SAS code to R?

I'm not sure, if I'm allowed to ask this.

I'm trying to translate below program to R code? Can you help? I appreciate your help indeed! Acknowledgement: Reeza helped write rand code below. Thanks Reeza!

``````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
;

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;``````

Acknow

Accepted Solutions
Solution
‎05-07-2018 11:15 AM
Super User
Posts: 23,791

## Re: Randomly generate decimal year. Translate SAS code to R?

You're allowed to ask, just unlikely to get an answer. I'd probably post it to an R forum instead.

All Replies
Solution
‎05-07-2018 11:15 AM
Super User
Posts: 23,791

## Re: Randomly generate decimal year. Translate SAS code to R?

You're allowed to ask, just unlikely to get an answer. I'd probably post it to an R forum instead.
Occasional Contributor
Posts: 19

## Re: Randomly generate decimal year. Translate SAS code to R?

Did Reeza just say "unlikely to get an answer", I think this is the first time you said something like this, you know everything !

Super User
Posts: 23,791

## Re: Randomly generate decimal year. Translate SAS code to R?

lol...not by a long shot

@nayakig wrote:
Did Reeza just say "unlikely to get an answer", I think this is the first time you said something like this, you know everything !

Super Contributor
Posts: 374

## Re: Randomly generate decimal year. Translate SAS code to R?

I know :-) Reeza consults for R language too :-)
Super User
Posts: 23,791

## Re: Randomly generate decimal year. Translate SAS code to R?

I do, but that I charge for

Sadly this is not my full time job and I should actually be doing that!

@Cruise wrote:
I know :-) Reeza consults for R language too :-)

Super Contributor
Posts: 374

## Re: Randomly generate decimal year. Translate SAS code to R?

Reeza, do you tutor doctoral students on programming in R for payment? I'm using age-period-cohort modelling for my dissertation project. Let me know if that's what you're familiar with. We can private chat as well if needed.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
• 6 replies
• 107 views
• 2 likes
• 3 in conversation