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

Hi there,

 

Is there a way to combine proc means with proc ttest across several variables to create a single table that gives mean, sd, median and iqr for different groups as well as a ttest.

This creates an approximation of what I want:

 

proc means data=sashelp.cars n mean stddev median q1 q3 prt;
class origin;
var msrp invoice MPG_Highway;run;

 

The difference is that I want origin as columns and the ttest to compare means and medians across origins:

 Asia     Europe     USA       
VariableNMeanStd DevMedianLower QuartileUpper QuartileNMeanStd DevMedianLower QuartileUpper QuartileNMeanStd DevMedianLower QuartileUpper QuartilePr > |t| MEDIANPr > |t| MEAN
MSRP15824741.3211321.0723032.5172002880012348349.825318.640590337805659514728377.4411711.98255202031033995pp
Invoice15822602.189842.9820949.5162652666012344395.0823080.3737575311875181514725949.3410518.72232171888130846pp
MPG_Highway15828.265826.77050327253112326.008134.16758826242914726.013615.396582262229pp

 

Many thanks

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

This produces something close to what you asked for.

 

proc summary data=sashelp.cars nway stackods;
class origin;
var msrp invoice MPG_Highway;
output out=_stats_ n= mean= stddev= median= q1= q3= prt= /autoname;
run;

I don't know any way to get the t-test of a median.

 

If you have to have the table laid out EXACTLY as you have shown, that will take a lot more work.

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

PROC MEANS produces an output data set. PROC TTEST produces an output data set. You merge them together and then PROC REPORT can produce the desired table.

--
Paige Miller
AliRKM
Obsidian | Level 7
Thanks @PaigeMiller. I am really new to this, do you mind providing example code?
I'm looking at about 20 variables which is why I would love an automated process.
PaigeMiller
Diamond | Level 26

This produces something close to what you asked for.

 

proc summary data=sashelp.cars nway stackods;
class origin;
var msrp invoice MPG_Highway;
output out=_stats_ n= mean= stddev= median= q1= q3= prt= /autoname;
run;

I don't know any way to get the t-test of a median.

 

If you have to have the table laid out EXACTLY as you have shown, that will take a lot more work.

--
Paige Miller
AliRKM
Obsidian | Level 7

Perfect - thank you.

Read some more - the t-test is a test of means so asking for a test of medians was a mistake on my part.

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!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 3720 views
  • 0 likes
  • 2 in conversation