turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- SAS DATES SELECTION

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-22-2009 05:01 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Fred_Gavin

09-22-2009 05:34 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-22-2009 09:34 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Fred_Gavin

09-23-2009 08:08 AM

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.

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(

* Test for holidays always on a specific date for a given year. ;

ELSE IF

HOLIDAY = 1;

ELSE DO;

* your additional logic. ;

END;

Scott Barry

SBBWorks, Inc.