Something like this should work:
data have;
call streaminit(12345);
do date='01JAN2022'd to '31DEC2024'd by 7;
Amount =rand('integer', 100, 200);
output;
end;
run;
%macro summarize4(year, qtr);
proc sql;
select "&year" as Year
,"&qtr" as Quarter
,sum(Amount) as Total
,round(avg(Amount),.1) as Average
from have
where year(date)=&year
and qtr(date)=&qtr
;
quit;
%mend;
%summarize4(2023,2)
%summarize4(2024,1)
Result:
| Year | Quarter | Total | Average |
|---|---|---|---|
| 2023 | 2 | 2020 | 155.4 |
| Year | Quarter | Total | Average |
|---|---|---|---|
| 2024 | 1 | 1934 | 148.8 |
@Sas_rookie_sa wrote:
I have a data set with dates from all year long. I'm trying to set up a macro to pass a sysparm to only evaluate data with a given year and a given quarter
Are you going to do this repeatedly, such that all year/quarter combinations in your data set are "evaluated" (whatever that means)?
No need for a macro in this case. This will get the job done (it is calculating means, but other statistics are available):
proc summary data=have nway;
class date;
var amount;
format date yyq6.;
output out=want mean=;
run;
In fact, this seems like a more efficient approach than repeatedly calling a macro, it should execute much faster, especially on large data sets. Please explain how you would use such a macro.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.