BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Amalik
Calcite | Level 5

Hi,

 

My data looks like the first two variables i.e permno and date and I want to create a third variable winID as follows,it can be thought of as non-overlapping rolling windows but then again the size of the window is dependent on the number of days in a month and that is why I am not getting how to handle it.

 

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

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Just test if the current month is different than the previous month.

data want ;
  set have ;
  by permno date;
  winid + (month(date) ne month(lag(date)));
run;

If you could potentially skip exactly 11 months then you might want to make it more complicated and use the INTNX() function instead.

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

View solution in original post

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

I am unsure I fully understand. Try:

  WINID + ( dif(DATE) ne 0 | dif(PERMO) ne 0 );

Tom
Super User Tom
Super User

Just test if the current month is different than the previous month.

data want ;
  set have ;
  by permno date;
  winid + (month(date) ne month(lag(date)));
run;

If you could potentially skip exactly 11 months then you might want to make it more complicated and use the INTNX() function instead.

  winid + (intnx('month',date,0.'b') ne intnx('month',lag(date),0,'b'));
Amalik
Calcite | Level 5

Thanks Tom, this solves my issue.

Amalik
Calcite | Level 5

Hi,

Can you please also suggest how to create a third variable say TIME that represents each day through 1jan00 to 31jan00 as just one month that is jan00 ?

 

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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