I'm generating mean and n statistics for two outcome variables, ip_count & bh_ed_count, by a third Yes/No categorical variable named "A" using proc means:
proc means data=ipdf_adults n mean;
where A in('Y','N');
by A;
var ip_count bh_ed_count;
output out=ipdf_adults_mean_a ;
run;
The results output listing for proc means is correct:
--------------------------------------------------------------- A=N ----------------------------------------------------------------
The MEANS Procedure
Variable Label N Mean
--------------------------------------------------
ip_count IP_COUNT 186 0.6021505
bh_ed_count BH_ED_COUNT 186 0.9301075
--------------------------------------------------
--------------------------------------------------------------- A=Y ----------------------------------------------------------------
Variable Label N Mean
--------------------------------------------------
ip_count IP_COUNT 54 0.5925926
bh_ed_count BH_ED_COUNT 54 1.2407407
--------------------------------------------------
However the output dataset incorrectly lists the mean values as 1:
A | _TYPE_ | _FREQ_ | _STAT_ | ip_count | bh_ed_count |
N | 0 | 186 | N | 186 | 186 |
N | 0 | 186 | MIN | 0 | 0 |
N | 0 | 186 | MAX | 5 | 48 |
N | 0 | 186 | MEAN | 1 | 1 |
N | 0 | 186 | STD | 1 | 4 |
Y | 0 | 54 | N | 54 | 54 |
Y | 0 | 54 | MIN | 0 | 0 |
Y | 0 | 54 | MAX | 4 | 9 |
Y | 0 | 54 | MEAN | 1 | 1 |
Y | 0 | 54 | STD | 1 | 2 |
Any ideas what's going on here? Thanks
My guess is rounding in the presentation, try changing the format of the data in the viewer or in a data step.
data ipdf_adults_mean_a;
set ipdf_adults_mean_a;
format ip_count bh_ed_count 12.4;
run;
If you want a different structure for the table, look into the STACKODS output.
My guess is rounding in the presentation, try changing the format of the data in the viewer or in a data step.
data ipdf_adults_mean_a;
set ipdf_adults_mean_a;
format ip_count bh_ed_count 12.4;
run;
If you want a different structure for the table, look into the STACKODS output.
Thanks Reeza, that fixed the problem!
And I can insert the format statement into proc means to save myself a step:
proc means data=ipdf_adults n mean;
format ip_count bh_ed_count 12.4;
where A in('Y','N');
by A;
var ip_count bh_ed_count;
output out=ipdf_adults_mean_a ;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.