Dear,
I need help in my code to get the output i need to create a dataset for my table. Please help. Thank you.
I am calculating n, mean, median, range by variables test,visit,trt
data one;
input id trt $ visit $ test $ bas val;
datalines;
1 a wk1 pul 2 3
2 b wk1 pul 3 6
3 c wk1 pul 4 9
4 a wk1 pul 3 7
5 b wk1 pul 3 7
6 c wk1 pul 3 7
1 a wk1 bp 10 12
2 b wk1 bp 12 14
3 c wk1 bp 14 16
4 a wk1 bp 12 14
5 b wk1 bp 14 16
6 c wk1 bp 16 18
1 a wk2 pul 2 3
2 b wk2 pul 3 6
3 c wk2 pul 4 9
4 a wk2 pul 3 7
5 b wk2 pul 3 7
6 c wk2 pul 3 7
1 a wk2 bp 10 12
2 b wk2 bp 12 14
3 c wk2 bp 14 16
4 a wk2 bp 12 14
5 b wk2 bp 14 16
6 c wk2 bp 16 18
;
proc means data=one n mean sum range median min max;
var val;
class test visit trta;
output out=two(keep=_stat_ trt visi test val where=(test='pul' and trt ^='' and visi ^=''));
run;
dataset output needed:
visit trt n mean median min max SD
wk1 a 2 5 5 3 7 2.82
wk1 b 2 6.5 6.5 6 7 0.7
wk1 c 2 8 8 7 9 1.4
wk2 a 2 5 5 3 7 2.82
wk2 b 2 6.5 6.5 6 7 0.7
wk2 c 2 8 8 7 9 1.4
Table output needed;
wk1(pul)
a b c
n 2 2 2
mean(SD) 5(2.82) 6.5(0.7) 8(1.4)
median 5 6.5 8
range(min,max) 3, 7 6, 7 7, 9
You got started correctly using PROC MEANS (or its alias proc summary).
But ...
Here's an analog using sashelp.shoes:
proc summary data=sashelp.shoes n mean sum range median min max nway;
class region subsidiary product;
var sales;
output out=two (drop=_type_ _freq_);
run;
proc sort;
by region subsidiary _stat_ product;
run;
proc transpose data=two out=want (drop=_name_ _label_);
by region subsidiary _stat_;
id product; /* Assign the product as the new variable name */
run;
Thank you very much for the code. But why the median and range values are not calculated with the code. Do you any suggestion
STACKODS
proc means data=sashelp.shoes n mean sum range median min max stackods nway;
class region subsidiary product;
var sales;
ods output summary=want;
run;
It didnt create the values because the statistics in the PROC MEANS statement control the display output, but you're capturing a different output when you use OUTPUT statement instead of ODS statement.
Look at Cynthia Zender's paper on Creating Complex Reports. It has exact examples with code on how to accomplish this task.
Use STACKODS option for your table, rather than a means and then transpose. See the documentation in PROC MEANS for an example or this SAS Note.
http://support.sas.com/kb/46/427.html
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.