BookmarkSubscribeRSS Feed
Amalik
Calcite | Level 5

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

1 REPLY 1
Patrick
Opal | Level 21

@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.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 574 views
  • 0 likes
  • 2 in conversation