Hi there,
I ran the following proc freq in SAS and got the SAS output as shown in the attached Word.doc
proc freq data=test;
tables (age_group gender)*disease/chisq norow nopercent relrisk;
Title 'How to export SAS output into Excel';
run;
I would like to get the results directly from SAS to Excel on a table as shown in the attached Excel file.
Is there a way to modify the proc freq in SAS to get the results as shown in the attached Excel file?
I have several variables beside age and gender and am I tiered of copy and paste.
it would be great if all the formating in the table of the attached Excel file can be done in SAS but if it is not possible getting the numbers and name of variables as shown would be great
all your help will be appreciate it
Thanks
I don't think anyone will open your attached files, however you can put your code where I have indicated
FILENAME out '~/folder/file.xlsx';
ods listing close;
ods excel file=out options(sheet_name='#byval1');
*your code goes here;
ods excel close;
ods listing;
Proc freq doesn't go as nicely as you'd like to Excel, PROC TABULATE will give you more control.
To get any output in Excel, wrap it with ODS EXCEL before and after and it will pipe all the results to Excel. You can control what sheets things go to as well as the sheet names.
ods excel file='/folders/myfolders/demo.xlsx' style=meadow options (sheet_interval='proc');
proc freq data = sashelp.class;
table age*sex / nopercent norow nocol;
run;
ods excel close;
Since you asking to put Chi-square p-values and relative risk information on the same row as other values you aren't going to get proc freq to do that.
Or without significant work, any other procedure. You would generate the output into two or more data sets, combine some how and then display.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.