- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much