BookmarkSubscribeRSS Feed
Fred_Gavin
Calcite | Level 5
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

19900101
19900102
19900104
.......

19910101
19910102
19910103

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
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

Scott Barry
SBBWorks, Inc.



Date Intervals, Formats, and Functions
http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/intervals_toc.htm

SAS Language Reference: HOLIDAY Function
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a003060817.htm


WORKING WITH SAS® DATE AND TIME FUNCTIONS
Andrew H. Karp
Sierra Information Services, Inc., San Francisco, California USA
http://www2.sas.com/proceedings/sugi23/Begtutor/p57.pdf

TS-668 - SAS Dates, Times, and Interval Functions
http://support.sas.com/techsup/technote/ts668.pdf
Fred_Gavin
Calcite | Level 5
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).

Thanks
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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;
ELSE DO;
* your additional logic. ;
END;


Scott Barry
SBBWorks, Inc.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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