DATA Step, Macro, Functions and more

Summing months in dates

Reply
N/A
Posts: 0

Summing months in dates

Hi there,

I'me havind some trouble summing some dates.

I have a table with a column with Begin_Date and another colunm with
Maturity_Lenght.

I need to create another column with the End_Date, by adding the
Maturity_Lenght to the Begin_Date.

Begin_Date Maturity_Lenght (month) End_Date

02-05-2008 1
02-06-2008

05-05-2008 3
05-08-2008
.....

How can I do that?

data mylib.txcp_copy;
SET mylib.txcurtoprazo;
IF Prazo='D01' THEN DO
End_Date=Data_valor+1;
END;
IF Prazo='D07' THEN DO
End_Date=Data_valor+7;
END;
IF Prazo='D14' THEN DO
End_Date=Data_valor+14;
END;

/* adding 3 months to the iniciao date (data_valor)*/
IF Prazo='M03' THEN DO

end_date=intnx('month',Data_Valor,3,"sameday");

END;
run;
N/A
Posts: 0

Re: Summing months in dates

Posted in reply to deleted_user
Your maturity length appears to be a character variable, which is probably part of the problem that led you down this path.

I would check this value for its first character and if it is "D" then I would set the interval type to be "Day" and retrieve the other part of the month as a number with something like

DAYS = Input( Substr( LENGTH, 1, 2), 2.);

Then calculate the new end date with an appropriate call to the IntNx() function.

You should also use "Else If" where you have mutually exclusive conditions. It creates neater code that executes in marginally less time.

Kind regards

David
N/A
Posts: 0

Re: Summing months in dates

Posted in reply to deleted_user
Thanks so much for your help.
Ask a Question
Discussion stats
  • 2 replies
  • 130 views
  • 0 likes
  • 1 in conversation