DATA Step, Macro, Functions and more

Export Statistics

Reply
Occasional Contributor
Posts: 17

Export Statistics

Hi,

 

If I'm doing a chisq test or proc logistic, how do I get the results in a data table that can be exported into excel? For example, for the code below, I would like to have the odds ratio, p-value, and confidence intervals in a table for excel export. Same question for proc logistic. 

 

DATA QUESTION;
INPUT GENDER $ RESPONSE $ COUNT;
DATALINES;
WOMEN YES 28
WOMEN NO 13
MEN YES 19
MEN NO 26

;

PROC FREQ DATA=QUESTION ORDER =DATA;
WEIGHT COUNT;
TABLES GENDER*RESPONSE / CHISQ RELRISK;
RUN;

 

proc logistic data = question desc;
class gender;
model response = gender;
run;

Super User
Posts: 19,822

Re: Export Statistics

1. You can direct the output to Excel 'automatically' (assumes SAS 9.4 TS1M3+)

 

ods excel file='mydata.xlsx' style=meadow;

<insert your SAS code here>;


ods excel close;

2. The second option is more manual unfortunately but if you're looking for production ready tables this will get you closer.

You would capture the tables you want and then proc print or proc report this out to an Excel file.

 

http://blogs.sas.com/content/iml/2017/01/09/ods-output-any-statistic.html

PROC Star
Posts: 1,760

Re: Export Statistics

Add this to you code and look in the log. You'l lsee all the outputs you can redirect.

 


ods trace on;

proc logistic data = question desc;
class gender;
model response = gender;
run;

ods trace off;

From there you can use ODS OUTPUT statements to capture the bits you want.

 

http://support.sas.com/documentation/cdl/en/odsug/69832/HTML/default/viewer.htm#p1fpt3uuow90o3n155hs...

http://support.sas.com/documentation/cdl/en/odsug/69832/HTML/default/viewer.htm#p0oxrbinw6fjuwn1x23q...

Occasional Contributor
Posts: 17

Re: Export Statistics

Is there a way to do this without using the ODS excel? I want to export to an already existing excel file and create new tabs, rather than create a whole new file each time. 

 

thank you. 

Super User
Posts: 19,822

Re: Export Statistics


Woop122 wrote:

Is there a way to do this without using the ODS excel? I want to export to an already existing excel file and create new tabs, rather than create a whole new file each time. 

 

thank you. 


Not easily but it could be done. You'd have to capture the tables of interest using ODS anyways and then export them manually using PROC EXPORT.

 

Here's a link on how that can be done:

http://blogs.sas.com/content/iml/2017/01/09/ods-output-any-statistic.html

Super User
Posts: 19,822

Re: Export Statistics

I guess...the answer is the same as above Smiley Happy
Ask a Question
Discussion stats
  • 5 replies
  • 152 views
  • 0 likes
  • 3 in conversation