Hello programmers,
I have a dataset in which only the year of death relative to baseline (not the actual days till death ) is provided.
For example. If yrofdeath=1, the person died in year 0-1 (within 365 days);
if yrofdeath=2, the person died in year 1-2 (days 366-730)
If yrofdeath=3, the person died in year 2-3(731 -1096)
I want to use a rauni function to assign the number of days until death based off the given yrofdeath in the dataset and to round it up using the round function. I have read papers and texts on ranuni but i have no idea how to approach this particular problem. How can i convert 0-1 to 0-365? I know for yrofdeath 2 and 3, i also have to add 365 and 730 respectively. How do i do this?
data one;
input site id yrofdeath cause;
datalines;
3 1 2 195
3 19 3 414
3 26 2 431
3 27 2 414
3 29 1 414
3 40 2 414
3 42 3 188
3 52 1 557
3 55 3 429
3 56 2 153
3 56 2 153
3 59 3
3 67 2 496
3 79 2 414
3 80 3 440
3 81 2 157
3 82 2 199
3 94 1 414
3 95 1 414
3 99 2 436
3 105 1 507
3 119 2 153
3 127 1 414
3 143 3 599
3 145 3 410
3 158 2 162
3 165 1 496
3 172 1 414
3 177 3 481
3 188 3 174
3 199 3 414
3 202 2 414
3 203 1 185
3 203 1 185
3 211 3 518
3 220 2 153
3 223 2 154
3 226 1 414
3 233 2 429
3 243 3 402
3 251 1 145
3 266 3 162
3 269 3 429
3 271 3 410
3 274 3 414
3 281 1 518
3 289 3 575
3 296 2 496
; run;
I don't think you have to use Ranuni here. Simply do
data Two;
set One;
dayofdeath=(yrofdeath-1)*365+rand('integer', 1, 365);
run;
I don't think you have to use Ranuni here. Simply do
data Two;
set One;
dayofdeath=(yrofdeath-1)*365+rand('integer', 1, 365);
run;
@PeterClemmensen Your solution is superior as it will work for any year of death and not restricted to 1, 2 and 3. Simple and elegant solution.
Glad you like it 🙂
Thank you very much!
DATA Processed;
Set One;
IF YrOfDeath = 1 THEN DateDeath = RAND("integer",0,365);
ELSE IF YrOfDeath = 2 THEN DateDeath = RAND("integer",366,730);
ELSE DateDeath = RAND("integer",731, 1095);
RUN;
Thank you very much for the solution!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.