BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sathish_jammy
Lapis Lazuli | Level 10

Dear Experts,

 

I want to calculate the Surgery_date value from the Surgery_Duration.

Kindly go through the given sample dataset.

data have;
input ID Record_date mmddyy10. Duration DuratIn$.;
format Record_date mmddyy10.;
cards;
101 03/05/2001 7.6 Years
102 04/02/2001 6 Months
103 03/08/2003 2.06 Years
;

Expected OP:

IDRecord_dateDurationDuratInDateonSurg
10103/05/20017.6Year09/05/2008
10204/02/20016Month10/02/2001
10303/08/20032.06Year03/14/2005

 

Please Suggest some ideas to solve the case.

Much Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

Maybe something like this, but i am not sure that i fully understood the decimal place and how they should be used in the calculation.

data want;
   set have;

   attrib DateonSurg length=8 format=mmddyy10.;

   select (DuratIn);
      when ('Years') do;
         y = int(Duration);
         m = int((Duration - y) * 10);
         d = int((Duration - y - m/10) * 100);
      end;
      when ('Months') do;
         y = 0;
         m = int(Duration);
         d = 0; /* maybe wrong, no data to check */
      end;
      otherwise put 'ERROR: DuratIn' DuratIn 'is not yet implemented';
   end;

   DateOnSurg = intnx('Year', Record_date, y, 's');
   DateOnSurg = intnx('month', DateOnSurg, m, 's');
   DateOnSurg = intnx('day', DateOnSurg, d, 's');

   drop y m d;
run;

View solution in original post

9 REPLIES 9
andreas_lds
Jade | Level 19

In the last line of your example, you don't add 2.06 years, but 2 years an 6 days, is this correct?

 

data have;
input ID Record_date mmddyy10. Duration DuratIn$.;
format Record_date mmddyy10.;
cards;
101 03/05/2001 7.6 Years
102 04/02/2001 6 Months
103 03/08/2003 2.06 Years
;

Is this the version of your data we should use, or will there be further changes?

Sathish_jammy
Lapis Lazuli | Level 10

Sorry for an inconvenience @andreas_lds 

You are absolutely right (2.6 years). There are no further changes required.

 

I have to calculate the surgery date using the Record_date and Surgery_Duration. That's it

 

Thanks!

 

andreas_lds
Jade | Level 19

Maybe something like this, but i am not sure that i fully understood the decimal place and how they should be used in the calculation.

data want;
   set have;

   attrib DateonSurg length=8 format=mmddyy10.;

   select (DuratIn);
      when ('Years') do;
         y = int(Duration);
         m = int((Duration - y) * 10);
         d = int((Duration - y - m/10) * 100);
      end;
      when ('Months') do;
         y = 0;
         m = int(Duration);
         d = 0; /* maybe wrong, no data to check */
      end;
      otherwise put 'ERROR: DuratIn' DuratIn 'is not yet implemented';
   end;

   DateOnSurg = intnx('Year', Record_date, y, 's');
   DateOnSurg = intnx('month', DateOnSurg, m, 's');
   DateOnSurg = intnx('day', DateOnSurg, d, 's');

   drop y m d;
run;
Sathish_jammy
Lapis Lazuli | Level 10

Dear @andreas_lds  . Your code works well.

 

what is the alternate line if Days exist for

d = int((Duration - y - m/10) * 100);

  

andreas_lds
Jade | Level 19

@Sathish_jammy wrote:

Dear @andreas_lds  . Your code works well.

 

what is the alternate line if Days exist for

d = int((Duration - y - m/10) * 100);

  


Sorry, but i don't understand the question.

Criptic
Lapis Lazuli | Level 10

I would suggest to calculate the number of days and then just adding that to the record_date to get your DateonSurg.

Ksharp
Super User

Here could give you a start.

 

data have;
input ID Record_date : mmddyy10. Duration DuratIn $;
format Record_date mmddyy10.;
cards;
101 03/05/2001 7.6 Years
102 04/02/2001 6 Months
103 03/08/2003 2.6 Years
;

data want;
 set have;
 if DuratIn='Years' then do;
   n=ceil(duration);
   do i=Record_date to intnx('year',Record_date,n);
    if round(yrdif(Record_date,i,'act/act'),0.1)=round(Duration,0.1) then do;
     want=i;leave;end;
   end;
 end;
 format want mmddyy10.;
run;

Sathish_jammy
Lapis Lazuli | Level 10

Dear @Ksharp 

Thanks for your time and consideration. Your code works well for Year rows.

The Month parameter looks empty.

Could you please go through the month parameter.

 

Thanks in advance!

Ksharp
Super User

If you want take .6 as semi-year , . 2 as two months ,

I think @andreas_lds  has already given you great solution.

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
  • 9 replies
  • 800 views
  • 3 likes
  • 4 in conversation