I’m new to the macro facility and was trying my hand at writing a code that would give me frequency tables for different products by different years. The code I wrote gives me frequencies for all the products instead of selecting the product and year combinations I specify in the macro. Can anybody please correct the program?
Thanks!
data fruits;
set fruitdata;
if date gt 'XXX'd and date lt 'XXX'd then year= '2007';
if date gt 'XXX'd and date lt 'XXX'd then year= '2008';
if date gt 'XXX'd and date lt 'XXX'd then year= '2009';
if fruit= ‘orange’ then product= '1'; else product ='0';
if fruit= ‘apple’ then product= '2'; else product ='0';
if fruit= ‘pear’ then product= '3'; else product ='0';
run;
%macro test(year=, product=);
proc freq data= fruits;
table fruit;
title ‘Sale of product& in year&';
run;
%mend;
%test(year= '2007', product= '1');
%test(year= '2007', product= '2');
%test(year= '2007', product= '3');
%test(year= '2007', product= '1');
%test(year= '2007', product= '2');
%test(year= '2007', product= '3');
%test(year= '2009', product= '1');
%test(year= '2009', product= '1');
%test(year= '2009', product= '1');
... View more