Hi all!
I use to copy every single data from a result output into word tables for scientific publications, but this is actually time consuming.
I wonder if there is a faster procedure.
I attach a sample datastep for your help.
data graze;
length GrazeType $ 10;
input GrazeType $ WtGain @@;
datalines;
controlled 45 controlled 62
controlled 96 controlled 128
controlled 120 controlled 99
controlled 28 controlled 50
controlled 109 controlled 115
controlled 39 controlled 96
controlled 87 controlled 100
controlled 76 controlled 80
continuous 94 continuous 12
continuous 26 continuous 89
continuous 88 continuous 96
continuous 85 continuous 130
continuous 75 continuous 54
continuous 112 continuous 69
continuous 104 continuous 95
continuous 53 continuous 21
;
then perform ttest
proc ttest data=graze;
class GrazeType;
var WtGain;
run;
and obtain this results
Here I come to my point:
is there a way to automatically obtain the following output from the above results?
Variables | Group1 | Group2 | p-value |
WtGain | 75.2+/-33.8 | 83.1+/-30.5 | 0.49 |
Similarly for proc freq, obviously as count (%)
I use SAS on demand for academics.
Never heard of Add-in for MSOffice! this sounds nice!
Hi @antor82,
Here is how you can extract the desired statistics from ODS output datasets as mentioned by @LinusH:
ods output conflimits=cl ttests=tt equality=ev; proc ttest data=graze; class GrazeType; var WtGain; run; data want(keep=Variable Gr: p_:); set cl(obs=2) ev tt end=last; array Group[2] $15; if _n_<=2 then group[_n_]=catx('±',round(mean,0.1),round(stddev,0.1)); else if _n_=3 then pf=probf; else if Variances='Equal' then pte=probt; else ptu=probt; if last; p_value=ifn(pf>0.05,pte,ptu); format p_value pvalue6.2; retain Gr: p:; run;
Result:
Variable Group1 Group2 p_value WtGain 75.2±33.8 83.1±30.5 0.49
[EDIT: Added Variable in the KEEP= dataset option to include it in the result.]
Similarly for PROC FREQ, where the OUT= dataset is sufficient:
proc freq data=graze; tables grazetype / out=frq; run; data want2(keep=GrazeType cntpct); set frq; length cntpct $12; cntpct=put(count,4.)||' ('||put(percent,4.1)||')'; label cntpct='Count (%)'; run;
Result:
GrazeType Count (%) continuous 16 (50.0) controlled 16 (50.0)
Thank You!
This works perfectly for 1 variable dataset.
(I've succeeded in adding also the column with Variable name - that for me is a great achievement!🤣)
I've tried with one of my datasets with lots of variables but I obtain only one raw with some statistics that actually I do not not where they come from..... seems some sort of sums ... I cannot explain.
As far as proc freq is concerned, would You mind to provide me with a datastep that puts results in one row? adding also a p-value?
Tks in advance
@antor82 wrote:
I've tried with one of my datasets with lots of variables ...
Can you post an example of such a dataset (e.g., with two or three variables) and what type of output you want to get from that?
@antor82 wrote:
As far as proc freq is concerned, would You mind to provide me with a datastep that puts results in one row? adding also a p-value?
How many categories are there and what hypothesis (e.g. "equal proportions") do you want to test?
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.