I don't see how to reconcile your description of a data step with my problem. The data step, as far as I know, takes a list of datasets as input and produces a dataset, but that is not what I'm after here: My list is a set of categorical variables from a dataset and the function takes a variable and produces a dataset. So, "Data Step": (dataset_1, ..., dataset_n) -> dataset, but I want "Wanted_Function": (variable, dataset) -> dataset where variable is a column of the input dataset. Since I have a working solution, I'm really interested in knowing if there are built-in functions or other solutions I might be missing that can clean up my code and the amount of datasets produced. For example, if my dataset my_data looked like: Sex Region Salary M A 10000 M B 15000 F A 11000 F A 14000 I would want a dataset want_data that looked like Category Count Avg_Salary M 2 12500 F 2 12500 A 3 12500 B 1 11667 I can create this in SQL, but as I said, it's ugly - it builds a lot of intermediate datasets (here, just two - group_by_Sex, group_by_Region) that I don't want to keep and the union statement gets messy when you start incorporating more and more categorical variables. %macro summary_table(categorical_variable); create table group_by_&categorical_variable as select &categorical_variable as category, count() as count, avg(Salarly) as Avg_Salary from my_data group by &categorical_varialble; %mend; proc sql noprint; %summary_table(Sex); %summary_table(Region); create table want_data as (select * from group_by_Sex) union (select * from group_by_Region); quit;
... View more