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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.