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

I have a list of variables stored in the macro &relevant vars. I want to see the mean value of each of these variables (spread across the columns) grouped by a variable called cluster.

I ran a code as follows :

proc tabulate data = work.cluster_data_with_var_pred;
	var CLUSTER;
	table (CLUSTER)*(MEAN), &relevant_vars;
run;

It turns out that I cannot have the reference mentioned there. I tried a simple proc means but that creates a messy table where the relevant_vars just repeat rows for each cluster value instead of running across as columns Can anyone help me figure out another way to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Seems like a proc means would be enough?

proc means data=.... MEAN;
class cluster;
var &relevant_vars;
run;

Your mean belongs with the stats, not with the cluster. See if this gets you closer.

Proc tabulate data=....;
class CLUSTER;
var &relevant_vars;
table (CLUSTER), (&relevant_vars)*Mean;
run;

View solution in original post

3 REPLIES 3
Reeza
Super User
Seems like a proc means would be enough?

proc means data=.... MEAN;
class cluster;
var &relevant_vars;
run;

Your mean belongs with the stats, not with the cluster. See if this gets you closer.

Proc tabulate data=....;
class CLUSTER;
var &relevant_vars;
table (CLUSTER), (&relevant_vars)*Mean;
run;
aalluru
Obsidian | Level 7

Oh yes! The proc tabulate you sent worked perfectly. I wanted the variable list to run along the columns, that's why I scrapped the proc means idea. Thank you so much!

PeterClemmensen
Tourmaline | Level 20

I think what you want to do is this. I just replicated the problem using SASHELP.CLASS.

 

%let relevant_vars = height weight;

proc tabulate data = sashelp.class;
   class sex;
   var &relevant_vars;
   table sex, (&relevant_vars)*mean;
run;

 

Result:

 

Capture.PNG

 

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
  • 1138 views
  • 2 likes
  • 3 in conversation