Macro Problem

Reply
Contributor
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


Thanks

Sarvendra

Super Contributor
Posts: 333

Re: Macro Problem

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;

run;

%mend freq;

%freq(temp, A, D):

%freq(temp, B, D):

%freq(temp, C, D):

EJ

Super User
Posts: 10,483

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.

Contributor
Posts: 20

Re: Macro Problem

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
  • 182 views
  • 0 likes
  • 3 in conversation