- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I'm not sure how to find the differences in mean age between groups with standard deviation for a data file formatted in this layout.
Age Group Frequency
0 A 27
0 B 42
1 A 109
1 B 22
2 A 65
2 B 72
...
What I originally did was multiply frequency with age and totaled it, and divided by total frequency for that group, however, I'm not sure if there is a more efficient way.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello @vuhandrew and welcome to the SAS Support Communities!
@vuhandrew wrote:
I'm not sure how to find the differences in mean age between groups with standard deviation for a data file formatted in this layout.
I think you're looking for two statistics which are part of PROC TTEST output (highlighted in red below).
data have;
input Age Group :$1. Frequency;
cards;
0 A 27
0 B 42
1 A 109
1 B 22
2 A 65
2 B 72
;
ods select statistics;
proc ttest data=have;
class group;
freq frequency;
var age;
run;
Result:
Variable: Age Group Method N Mean Std Dev Std Err Minimum Maximum A 201 1.1891 0.6512 0.0459 0 2.0000 B 136 1.2206 0.8919 0.0765 0 2.0000 Diff (1-2) Pooled -0.0315 0.7574 0.0841 Diff (1-2) Satterthwaite -0.0315 0.0892
Edit: Needless to say, you can write these statistics to a dataset (e.g. WORK.STATS) for further processing or simply to see more decimals. Just insert an ODS OUTPUT statement into or before the PROC TTEST step:
ods output statistics=stats;
proc print data=stats noobs label;
where method=:'P';
format _numeric_ best17.;
var mean stddev;
label mean='Difference in mean age (A - B)';
run;
Result:
Difference in mean age (A - B) Std Dev -0.03153350892596 0.75744715265964
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello @vuhandrew and welcome to the SAS Support Communities!
@vuhandrew wrote:
I'm not sure how to find the differences in mean age between groups with standard deviation for a data file formatted in this layout.
I think you're looking for two statistics which are part of PROC TTEST output (highlighted in red below).
data have;
input Age Group :$1. Frequency;
cards;
0 A 27
0 B 42
1 A 109
1 B 22
2 A 65
2 B 72
;
ods select statistics;
proc ttest data=have;
class group;
freq frequency;
var age;
run;
Result:
Variable: Age Group Method N Mean Std Dev Std Err Minimum Maximum A 201 1.1891 0.6512 0.0459 0 2.0000 B 136 1.2206 0.8919 0.0765 0 2.0000 Diff (1-2) Pooled -0.0315 0.7574 0.0841 Diff (1-2) Satterthwaite -0.0315 0.0892
Edit: Needless to say, you can write these statistics to a dataset (e.g. WORK.STATS) for further processing or simply to see more decimals. Just insert an ODS OUTPUT statement into or before the PROC TTEST step:
ods output statistics=stats;
proc print data=stats noobs label;
where method=:'P';
format _numeric_ best17.;
var mean stddev;
label mean='Difference in mean age (A - B)';
run;
Result:
Difference in mean age (A - B) Std Dev -0.03153350892596 0.75744715265964
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your help! I really appreciate it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you need simple summary statistics for each level of group variable(s) you can use one of the procedures such as Means or Summary with the count as Freq variable.
proc means data=have; class group; var age; freq frequency; run;