BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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;
2 REPLIES 2
deleted_user
Not applicable
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
deleted_user
Not applicable
Thanks so much for your help.

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
  • 2 replies
  • 721 views
  • 0 likes
  • 1 in conversation