Hi guys, who can help me to figure out the following problem.
I wanna calculate 1 calendar year return for 2700 firms. So the date to be selected from time series for each firm is like
if my event date is 19910103, and one year return is ln(19910103)-ln(19900103), however it might be 19910103 is a holiday, not traded. So I want to select 19900104 instead. How can I do it in a generalized way that can perform 2700 simultaneously if same problem occurs to other firms.
Thank you very much first.
Message was edited by: Fred_Gavin
You will want to look at using SAS date-related functions such as INTNX, HOLIDAY (moved to Base SAS with SAS 9.2), INTCK, MDY, and possibly others in order to adjust your SAS DATE (numeric) variable - you weren't actually clear that you have SAS numeric variables which represent your date values (though you demonstrated a "formatted" value yyyymmdd).
The SAS support http://support.sas.com/ website has SAS-hosted documentation and supplemental technical / conference topic-related reference material on this type of discussion.
Thanks for the suggestion. But the only function manual seems not that helpful.
As the data not balanced, with 2700 firms, I have to consider the same day on the last calender year is holiday or not, and SAS functions only calculate the balanced days between two dates (say, number of week days between two days), but there are public holidays or local holidays involved. On those days, stock market is not traded.
Therefore I can define the day "today" ie. my event date, and if the last calendar date does exist, then I can define or extract as well. But I dont know how to extract if the last calendar date does not exist, but use next available date instead. (See my first post).
It's important that you clearly understand how SAS DATE variables are counted. A value of zero (numeric) is 01-Jan-1960 and 02-Jan-1960 is a value of 1. Therefore you can increment / decrement your "event" date simply by applying +1 or -1, if needed. Also there are other functions INTNX if the date calculation is more complex. It's time to invest reading about SAS date variables from the DOC links provided.
Also....as I do with dates and holidays:
You can introduce your own holiday dates expressed either as a ddmmm (a formatted value) or a specify date (literal constant) - here is a small code sample:
* Test for holidays always on the same date of the year. ;
IF PUT(,date5.) in ('23JAN','14APR','22MAY') THEN HOLIDAY = 1;
* Test for holidays always on a specific date for a given year. ;
ELSE IF in ('ddmmmyyyy'D,'ddmmmyyyy'D,'ddmmmyyyy'D) THEN
HOLIDAY = 1;
* your additional logic. ;