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;
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
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.
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.
@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
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.