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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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