BookmarkSubscribeRSS Feed
Filipvdr
Pyrite | Level 9

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

1 REPLY 1
manojinpec
Obsidian | Level 7

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-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
  • 1 reply
  • 622 views
  • 0 likes
  • 2 in conversation