Creating a lagged variable
Posted: 18 October 2011 12:25 PM   [ Ignore ]
Newbie
Rank
Total Posts:  7
Joined  2011-10-18

Could you provide an example of how to create a lagged variable in SAS?

Profile
 
 
Posted: 18 October 2011 01:06 PM   [ Ignore ]   [ # 1 ]
Sr. Member
RankRankRankRank
Total Posts:  169
Joined  2011-09-20

http://www.wrds.us/index.php/repository/view/7

look at this example.

i think if you have a var named GVKEY

then lag(GVKEY) will give you the lagged GVKEY.

 Signature 

Zenghui
A humble student of business

Profile
 
 
Posted: 18 October 2011 01:12 PM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  7
Joined  2011-10-18

What about if the variable is a date?  When I try to lag a date variable I end up with something that does not make sense.  Thanks for your help.

Profile
 
 
Posted: 18 October 2011 01:35 PM   [ Ignore ]   [ # 3 ]
Sr. Member
RankRankRankRank
Total Posts:  169
Joined  2011-09-20

http://www.wrds.us/index.php/tutorial/view/18

look at this example.

SAS code:
a.datadate -5 <= b.FPEDATS <= a.datadate +5

it may work, you just use date -1 to lag it.

 Signature 

Zenghui
A humble student of business

Profile
 
 
Posted: 19 October 2011 04:02 AM   [ Ignore ]   [ # 4 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

Hi,

wciconte - 18 October 2011 01:12 PM

What about if the variable is a date?  When I try to lag a date variable I end up with something that does not make sense.  Thanks for your help.

Could you tell us a bit more?

With ‘leading’ and ‘lagging’ I would think that you would like to have the ‘next’ or ‘previous’ value of a variable.
For example, if you have Compustat data and want to scale by beginning of year assets you will need the end-of-year assets of the previous year.

If you have a date variable (say earnings announcement date) and want to know the previous day, then you can subtract 1 to get the previous date.

INTNX is a good function for for date manipulation.
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212700.htm

If a date variable does not make sens - it could be it is ‘formatted’ as a number.
add:
FORMAT yourVariable date.;

try this to see the difference:
options yearcutoff=1950;
data _null_;
  a=‘26oct02’d;
  put ‘SAS date=‘a;
  put ‘formatted date=‘a date9.;
run;

 

hope this helps,

Joost

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile