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

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

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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;

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

6 REPLIES 6
user24feb
Barite | Level 11

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;

PTD_SAS
Obsidian | Level 7

Thank you, helpful hints.

Fethon

Jagadishkatam
Amethyst | Level 16

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
PTD_SAS
Obsidian | Level 7

Thanks, good hints.

mkeintz
PROC Star

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;

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
PTD_SAS
Obsidian | Level 7

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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