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

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;


 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

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;
koyelghosh
Lapis Lazuli | Level 10

@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.

PeterClemmensen
Tourmaline | Level 20

Glad you like it 🙂

ChuksManuel
Pyrite | Level 9

Thank you very much!

 

koyelghosh
Lapis Lazuli | Level 10
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;
ChuksManuel
Pyrite | Level 9

Thank you very much for the solution!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 687 views
  • 4 likes
  • 3 in conversation