BookmarkSubscribeRSS Feed
lalohg
Quartz | Level 8

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

 

5 REPLIES 5
ghosh
Barite | Level 11

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;
Reeza
Super User

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;
ballardw
Super User

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.

 

lalohg
Quartz | Level 8
Hi ballardw,
Thanks for your email.
Is there a way to get the column percentage in a New column next to The
frequency in Excel after I get rid of the relative risk and chi-square
option in proc freq?

Thanks

Reeza
Super User
I would suggest using the ODS output tables instead that's how they're outputted.

See an example here. Use PROC PRINT to display the final table only.
https://gist.github.com/statgeek/e0903d269d4a71316a4e

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 2270 views
  • 2 likes
  • 4 in conversation