I am trying to write a macro code that generates average sales for a particular year. Say today I want report for year=2008 and tomorrow for year=2009. The data has Order_date variable which is in format mmddyy10.
I am trying to achieve that by the following code:
%macro yearly(yr=%sysfunc(year("&sysdate"d ));
proc means data=salesxls;
class &yr;
where year(order_date) == &yr;
title "yearly avg sales for &yr";
run;
%mend yearly;
This is not working. The reason could be the %sysfunc I used to extract the year. Any help would be appreciated. P.S A Macro newbie here
EDIT: The code for single year that works is as follows:
data new;
set work.salesxls;
yr=year(Order_date); /** I extracted the year from Order_date)**/
run;
proc means data=new mean;
class yr;
var total_retail_price;
where yr=2008;
run;
In the code above I first created a data set which has extracted year. Then I used that data for proc means procedure.