Hello,
My dataset looks likes this:
DATE MONTH VALUE
01032011 MAR2011 8.50
02032011 MAR2011 8.50
02032011 MAR2011 5.50
02032011 MAR2011 8.50
14032011 MAR2011 7.50
24032011 MAR2011 9.00
24042011 APR2011 8.50
24042011 APR2011 8.50
26042011 APR2011 2.50
24042011 APR2011 3.50
16052011 MAY2011 2.50
24052011 MAY2011 13.50
25052011 MAY2011 4.50
26052011 MAY2011 3.50
27052011 MAY2011 2.50
25062011 JUN2011 10.50
26062011 JUN2011 13.50
27062011 JUN2011 12.50
28062011 JUN2011 13.50
According to 2 macro variables i have to calculate floating averages/median/percentile.
%let calc = average;
%let bin = 3;
The number of bin is in months. So for this example if i want to calculate the number for JUN2011 the number has to be calculated on the values of APR , MAY and JUN. If the variable bin is 2 i have to calculate JUN on JUN and MAY , MAY on APR and MAY and so on..
Could anyone set me on my way? I have no idea how to start on this one.
Regards,
Filip
options mlogic mprint symbolgen;
data have;
input date date9. value 8.2;
cards;
01mar2011 8.50
16may2011 2.50
25jun2011 10.5
;
run;
%macro tot(calc=mean,bin=3,month=06);
proc means data=have(where=(date<= mdy(&month.,1,2011) and date >=intnx('mon',mdy(&month.,1,2011),-&bin.,'beg'))) ;
var value;
output out=want &CALC. = &CALC.VALUE;
run;
%mend;
%tot;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.