Hi there,
I am trying to get mean, median and P95 using Proc means in a desired format such as mean_pulse as integer and P50 and P95
with one decimal. Can some body help me to modify my code to get the desired output.
data test;
input id pulse;
cards;
1 2
4 5
7 8
1 3
4 5
7 8
1 2
4 5
7 9
1 2
4 7
7 8
1 5
4 7
7 8
;
run;
proc sort data =test; by id; run;
proc means data =test noprint;
var pulse;
by id ;
output out=want (drop= _type_ _freq_) mean=mean_pulse p50=median_pulse p95=pctile_95;
run;
At present, I am getting median and P95 as whole number but I want with a decimal.
Regards,
proc means data =test noprint;
var pulse;
by id ;
output out=want (drop= _type_ _freq_) mean=mean_pulse p50=median_pulse p95=pctile_95;
format _numeric_ 10.1;
run;
Here is one way of doing that :
data want2;
set want;
format median_pulse pctile_95 10.1;
run;
You can put the format statement in PROC MEANS.
proc means data =test noprint;
var pulse;
by id ;
output out=want (drop= _type_ _freq_) mean=mean_pulse p50=median_pulse p95=pctile_95;
format _numeric_ 10.1;
run;
For your mean do want the value to actually be an integer or just appear as such? Apply a format such as F5. and the appearance will be rounded to an integer value. Or use a data step and actually round or truncate the value with ROUNT, FLOOR or CEIL functions.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.