BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mrahouma
Obsidian | Level 7

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.

image.png

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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).

Astounding
PROC Star

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 872 views
  • 1 like
  • 3 in conversation