BookmarkSubscribeRSS Feed
antor82
Obsidian | Level 7

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

Screenshot 2025-08-20 at 09.23.31.pngScreenshot 2025-08-20 at 09.23.47.png

 

Here I come to my point:

is there a way to automatically obtain the following output from the above results?

 

VariablesGroup1Group2p-value
WtGain75.2+/-33.883.1+/-30.50.49

 

Similarly for proc freq, obviously as count (%)

5 REPLIES 5
LinusH
Tourmaline | Level 20
I would start with storing the output in data sets, which can be obtained by using ODS:
https://documentation.sas.com/doc/en/statug/15.2/statug_ttest_details38.htm
Then exactly how to get them into Word is a different issue, and again ODS can be of help.
Are you in a single user environment, otr do you by chance have Add-in for MSOffice and/or access to a SAS Stored Process server?
Data never sleeps
antor82
Obsidian | Level 7

I use SAS on demand for academics.

Never heard of Add-in for MSOffice! this sounds nice!

FreelanceReinh
Jade | Level 19

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)

 

antor82
Obsidian | Level 7

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

FreelanceReinh
Jade | Level 19

@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?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 345 views
  • 5 likes
  • 3 in conversation