I strongly recommend against your macro approach. It's a sledgehammer for a staple. You can filter your years using either the proc freq or proc SQL method with a WHERE clause. This would also give you your dataset without the need to store your macro variables somewhere. Not to mention speed and clarity when editing your code for the future. proc sql; create table yearly_diagnosis1 as select year(diagdate) as year,count(zip) as count from cases where calculated year between year("&startdate"d) and year("&enddate"d) group by calculated year; quit; OR Proc freq data=cases noprint; where calculated year between year("&startdate"d) and year("&enddate"d); table diagdate*zip/out=yearly_diagnosis2; format diagdate year4.; run; To your question of how to store macro variables and append them, again a sledgehammer approach. I'd create a data set each loop and append it to the final data set and not go into macro variables at all. How would you know that nr_obs1 was aligned with year 2009? You'd have to do a calculation on the date to obtain that. If you really wanted you could do something like the following at the end of your loop, but before you exit the macro: data want; %do i = 1 %to &iterations; year=year("&startdate"d)+&i-1; Cases=&&&nr_obs&i.; output; %end; run;
... View more