Macro Problem

Posts: 20

Macro Problem

Hi All

pls guide me on

How to Write some macro code to do a PROC FREQ on a dataset called TEMP, running the macro 3 times to produce tables for variables A, B and C.   Use variable D to weight the results.   The weight, the name of the dataset and the names of the variables should be parameterised, so this macro could be used for any variables on any dataset



Super Contributor
Posts: 334

Re: Macro Problem

Posted in reply to Sarvendra

Here is a macro that would do what you want ... is there a reason you want a macro instead of just listing all the variables you need on the table statement?

%macro freq(ds,vars,wght);

proc freq data=&ds;

     table &vars;

     weight &wght;


%mend freq;

%freq(temp, A, D):

%freq(temp, B, D):

%freq(temp, C, D):


Super User
Posts: 13,583

Re: Macro Problem

And actually EJ's macro will work with a call like:

%freq(temp, A B C, D);

If the data set is large putting the all the table variables in one call will run faster as the data set will only be read once.

Though I would have made the parameters keyword parameters.

Posts: 20

Re: Macro Problem

Posted in reply to Sarvendra

Thanks a lot EJ and Ballard for the help.Actually I faced this question in one of SAS interviews so thats why asked.Smiley Happy

Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation