Help using Base SAS procedures

Grouping dates by bi-monthly groups

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

Grouping dates by bi-monthly groups

Would anyone suggest an algorithm to group dates by cponsecutive bi-monthly groups? I.e. similar to quarters but insteaed of 3 to have 2 month groups. For example, Jan-Feb 2014 would be B1 (similar to Q1 for quarters), Mar-Apr 2014 would be B2 etc.

Thanks,

Fethon Naoum


Accepted Solutions
Solution
‎08-19-2014 08:20 AM
Trusted Advisor
Posts: 1,018

Re: Grouping dates by bi-monthly groups

data want;

   set have;

    bimonth_date=intnx('month2',date,0,'beg');

   ** or ** ;
   bimonth_withinyear=   ceil(month(date)/2) ;

  ** or **

  bimonth_overall =    intck('month2','31dec1999'd,date);

run;

View solution in original post


All Replies
Super Contributor
Posts: 340

Re: Grouping dates by bi-monthly groups

Maybe like this:

Data A;
  Do i=1 To 2;
    Do j=1 To 12;
      Date=MDY(j,1,2000+i);
   Value=Round(Normal(1)*20+50);
   Output;
End;
  End;
  Format Date Date9.;
  Keep Date Value;
Run;

Proc Expand Data=A Out=B (Keep=Date B_Value);
  Convert Value = B_Value / Method = None Transformout = (Cmovave 2);
Run;

Data B;
  Set B;
  If Mod(_N_,2) eq 1 Then Do;
    B_Value=B_Value*2;
Output;
  End;
Run;

Contributor
Posts: 71

Re: Grouping dates by bi-monthly groups

Posted in reply to user24feb

Thank you, helpful hints.

Fethon

Trusted Advisor
Posts: 1,137

Re: Grouping dates by bi-monthly groups

hope this is what you were expecting

proc format ;

value  mon 1-2='B1'

           3-4='B2'

           5-6='B3'

           7-8='B4'

           9-10='B5'

           11-12='B6';

run;

data test;

length qtr$10.;

   do m=1 to 12;

     date=mdy(m,1,2010);

     qtr=put(month(date),mon.);

     put qtr=;

   output;

   end;

run;

Thanks,

Jag

Thanks,
Jag
Contributor
Posts: 71

Re: Grouping dates by bi-monthly groups

Posted in reply to Jagadishkatam

Thanks, good hints.

Solution
‎08-19-2014 08:20 AM
Trusted Advisor
Posts: 1,018

Re: Grouping dates by bi-monthly groups

data want;

   set have;

    bimonth_date=intnx('month2',date,0,'beg');

   ** or ** ;
   bimonth_withinyear=   ceil(month(date)/2) ;

  ** or **

  bimonth_overall =    intck('month2','31dec1999'd,date);

run;

Contributor
Posts: 71

Re: Grouping dates by bi-monthly groups

Thanks, very smart with just one line of code! Exactly what I wanted.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 407 views
  • 3 likes
  • 4 in conversation