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

 

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