DATA Step, Macro, Functions and more

creating variables

Reply
Contributor
Posts: 51

creating variables

Hi,

 

I have the following data with first two variables only i.e permno and date. 

 

 

PERMNODATEWINIDTIME
11-Jan-001Jan-00
1Jan-00
131-Jan-001Jan-00
11-Feb-002Feb-00
….2Feb-00
128-Feb-002Feb-00
21-Jan-003Jan-00
3Jan-00
231-Jan-003Jan-00
21-Feb-004Feb-00
….4Feb-00
228-Feb-004Feb-00

 

I created the third variable winid using the following code as suggested by one of the community members. The variable winid is dependent on the number of days in a month and is created using the following code,

 

 winid + (intnx('month',date,0.'b') ne intnx('month',lag(date),0,'b'));

 

 My first question is how should I modify this code to create winid that takes into account every quarter rather than just the number of days in a month i.e 

 

PERMNODATEWINIDTIME
11-Jan-001Mar-00
1Mar-00
131-Mar-001Mar-00
11-Apr-002Jun-00
….2Jun-00
130-Jun-002Jun-00
21-Jan-003Mar-00
3Mar-00
231-Jan-003Mar-00
21-Feb-004Jun-00
….4Jun-00
228-Feb-004Jun-00

 

My second question is how can I create the fourth variable TIME such that it shows me just the last date of every window as suggested by my table above.

 

Thanks

Respected Advisor
Posts: 4,679

Re: creating variables

[ Edited ]

@Amalik

Do you understand the algorithm and functions you're already using?

 winid + (intnx('month',date,0.'b') ne intnx('month',lag(date),0,'b'));

 

If you do then it shouldn't be hard to understand that all you need to do is to change the interval from month to quarter.

 

As for this "time" variable: Function INTNX() allows you to shift dates to the beginning or end of a date/time/datetime interval like quarter.

Ask a Question
Discussion stats
  • 1 reply
  • 93 views
  • 0 likes
  • 2 in conversation