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:
ID | Record_date | Duration | DuratIn | DateonSurg |
101 | 03/05/2001 | 7.6 | Year | 09/05/2008 |
102 | 04/02/2001 | 6 | Month | 10/02/2001 |
103 | 03/08/2003 | 2.06 | Year | 03/14/2005 |
Please Suggest some ideas to solve the case.
Much Thanks!
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;
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?
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!
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;
Dear @andreas_lds . Your code works well.
what is the alternate line if Days exist for
d = int((Duration - y - m/10) * 100);
@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.
I would suggest to calculate the number of days and then just adding that to the record_date to get your DateonSurg.
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;
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!
If you want take .6 as semi-year , . 2 as two months ,
I think @andreas_lds has already given you great solution.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.