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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: