I want to create a sas macro so that it can be run for any airport. to calculate sum flights and sum passenger per that airport
I want to call the macro once for each of the 12 airports.
Please note that all airports names consist of 3 letters.
Looking at your data structure, I think it's more complex than using a BY statement. A macro could look like this:
%macro sum_airline (airline=);
proc means data=airtraffic;
var &airline.Flights &airline.Passengers;
output out=&airline.Summary sum=;
run;
%mend sum_airline;
Then you can use the macro for each airport:
%sum_airline (airline=BOS)
%sum_airline (airline=ATL)
Notice that this macro prints the results, and also creates a data set holding the sums.
For next time, a positive step you could take would be to write a program that processes one airline. No macro language involved. For example, it should be up to you to be able to code this much before macro language is involved:
proc means data=airtraffic sum;
var ATLFlights ATLPassengers;
run;
Since all the relevant procedures support by-group processing, no macro coding is necessary.
If you still think you need a macro, post the code that does one calculation.
And don't forget to give us usable example data (in a data step with datalines).
Looking at your data structure, I think it's more complex than using a BY statement. A macro could look like this:
%macro sum_airline (airline=);
proc means data=airtraffic;
var &airline.Flights &airline.Passengers;
output out=&airline.Summary sum=;
run;
%mend sum_airline;
Then you can use the macro for each airport:
%sum_airline (airline=BOS)
%sum_airline (airline=ATL)
Notice that this macro prints the results, and also creates a data set holding the sums.
For next time, a positive step you could take would be to write a program that processes one airline. No macro language involved. For example, it should be up to you to be able to code this much before macro language is involved:
proc means data=airtraffic sum;
var ATLFlights ATLPassengers;
run;
Thank you so much
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.