BookmarkSubscribeRSS Feed
aishajennifer1
Calcite | Level 5

I am trying to do the proc means by day and treatment but I am not finding the right

SubjectIDdaygroupvariable1_Meanvariable2_Meanvariable3_Medianvariable3_Median
20placebo22160
10treatment13110
30treatment21120
21placebo2254122
11treatment1572.5
31treatment1114.52
22placebo.1.0
12treatment21123
32treatment2114

4

 

Something like this:

 

Daygroupvariable1_Meanvariable2_Meanvariable3_Medianvariable3_Median
0treatment1.5   
1treatment1   
2treatment2   
0placebo2   
1placebo2   
2placebo    

 

I did the following:

proc sort data= have; by day group;

run;

 

proc means data = have out = stat;

by day group;

var Variable1_Mean -- Variable3_Median 

n= mean= lclm= uclm= median= min= max= nmiss=/autoname;

 

proc means data=have;

by day group;

var variable1_mean -- variable3_median;

output out=want n= mean= lclm= uclm= median= min= max= nmiss=/autoname;

run;

 

2 REPLIES 2
ed_sas_member
Meteorite | Level 14

Hi @aishajennifer1 

 

In my understanding, you want to compute the mean for each variable by group and day (e.g the mean of the 3 median, the mean of the 3 individuals means, etc). Is that right ?

So there is no need to compute other statistics like median, etc.

proc sort data= have;
	by group day ;
run;
 
proc means data=have mean noprint;
	class group day ;
	var variable1_Mean variable2_Mean variable3_Mean variable4_Median;
	ways 2;
	output out=want (drop=_type_ _freq_) mean= variable1_Mean variable2_Mean variable3_Mean variable4_Median;
run;
proc print;

 

subhroster
Fluorite | Level 6

You can use the NWAY option for this. Note that Proc means or summary will not calculate means for missing values, so you have to exclude the missing value. I have taken variable1_mean and median, You can include all the other variable in the VAR statement and also in the Mean and Median statements for the output.

Please refer to the link below for more details on Proc means.

 

https://www.9to5sas.com/proc-means/ 

 

data have;
 input subject day group $9. variable1_Mean;
 datalines;
2 0 placebo   2
1 0 treatment 1 
3 0 treatment 2 
2 1 placebo   2 
1 1 treatment 1 
3 1 treatment 1 
2 2 placebo   . 
1 2 treatment 2 
3 2 treatment 2
3 3 treatment 1
3 3 treatment 2
3 3 treatment 3
3 3 treatment 4
  
;
run;

proc summary data=have(WHERE=(variable1_Mean ^=.)) mean median nway;
 class group day;
 var variable1_Mean;
 output out=want (drop=_type_ _freq_) mean=variable1_Mean 
  median=variable1_Median;
run;
Subhro Kar
www.9to5sas.com

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 458 views
  • 0 likes
  • 3 in conversation