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
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;
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;
Thank you, helpful hints.
Fethon
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, good hints.
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;
Thanks, very smart with just one line of code! Exactly what I wanted.
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.
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.