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
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: