BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Pabster
Obsidian | Level 7

Hi all!

It seems to be a very simple quetion but I can't get around it.
I have obtained data from my data set with Proc means.

proc means data=Z_score2;
var X1 X2 X3 X4 X5 Z;
by Costat SIC1_4;
run;

 

But now I would like to export that proc means data into an excel file automaticaly. 

How can I proceed?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

There are many ways but I'll point out two methods:

 

1. Create an output data set and export the data set

2. Have your output directly sent to excel

 

1.  PROC MEANS + PROC EXPORT

 

proc means data=Z_score2 stackods;
var X1 X2 X3 X4 X5 Z;
by Costat SIC1_4;
ods output summary = want;
run;

proc export data=want outfile='/folders/myfolders/demo1.xlsx' dbms=xlsx replace;run;

2. ODS EXCEL

 

ods excel file='/folders/myfolders/demo2.xlsx' style=seaside;

proc means data=Z_score2;
var X1 X2 X3 X4 X5 Z;
by Costat SIC1_4;
run;

ods excel close;

@Pabster wrote:

Hi all!

It seems to be a very simple quetion but I can't get around it.
I have obtained data from my data set with Proc means.

proc means data=Z_score2;
var X1 X2 X3 X4 X5 Z;
by Costat SIC1_4;
run;

 

But now I would like to export that proc means data into an excel file automaticaly. 

How can I proceed?


 

View solution in original post

8 REPLIES 8
ballardw
Super User

If you have the SAS/Interface to PC Files:

 

ods excel file="<your path>\<yourfilename>.xlsx"
;

proc means data=Z_score2;
var X1 X2 X3 X4 X5 Z;
by Costat SIC1_4;
run;

ods excel close;

is likely simplest.

If you don't have Interface to PC files the use ODS tagsets.excelxp instead of ods excel.

You will get complaints from Excel about the file format not matching as tagsets.excelxp creates XML instead of XLSX native formats but hopefully can open it.

Reeza
Super User

There are many ways but I'll point out two methods:

 

1. Create an output data set and export the data set

2. Have your output directly sent to excel

 

1.  PROC MEANS + PROC EXPORT

 

proc means data=Z_score2 stackods;
var X1 X2 X3 X4 X5 Z;
by Costat SIC1_4;
ods output summary = want;
run;

proc export data=want outfile='/folders/myfolders/demo1.xlsx' dbms=xlsx replace;run;

2. ODS EXCEL

 

ods excel file='/folders/myfolders/demo2.xlsx' style=seaside;

proc means data=Z_score2;
var X1 X2 X3 X4 X5 Z;
by Costat SIC1_4;
run;

ods excel close;

@Pabster wrote:

Hi all!

It seems to be a very simple quetion but I can't get around it.
I have obtained data from my data set with Proc means.

proc means data=Z_score2;
var X1 X2 X3 X4 X5 Z;
by Costat SIC1_4;
run;

 

But now I would like to export that proc means data into an excel file automaticaly. 

How can I proceed?


 

Pabster
Obsidian | Level 7

@Reeza
Thank you very much the 2nd method is perfect!

by any chance do you also know how I could obtain all the data in ONE spreadsheet?

Because this proc means gives me around 100 different sets of data, as you can imagine trying to create graph afterwards might be a bit of a problem with 100tabs

Reeza
Super User
In that case, I'd highly recommend the first option instead, it will give you a single table that's much nicer to use to create your graphs. In fact, you can easily graph that within SAS if needed as well.
Pabster
Obsidian | Level 7

Yeah sadly I haven't reached the graph level in sas but I'll be looking into it soon! Thanks!

Reeza
Super User

Or you could modify it as:

 

ods excel file='/folders/myfolders/demo2.xlsx' style=seaside;

ods select none;
proc means data=Z_score2;
var X1 X2 X3 X4 X5 Z;
by Costat SIC1_4;
ods output summary=want;
run;
ods select all;

proc print data=want;
run;

ods excel close;
ballardw
Super User

@Pabster wrote:

@Reeza
Thank you very much the 2nd method is perfect!

by any chance do you also know how I could obtain all the data in ONE spreadsheet?

Because this proc means gives me around 100 different sets of data, as you can imagine trying to create graph afterwards might be a bit of a problem with 100tabs


If by "100 different sets of data" you mean separate displayed tables for each combination of your variables on the BY statement you can try changing BY to CLASS. That will still provide summaries grouped by the variables but the results are a single table.

For example:

proc means data=sashelp.class;
   class sex age;
   var height weight;
run;

A secondary benefit is CLASS variables do not need to be sorted as BY variables do.

Differences in output data sets are available as you can get additional summaries of 1) data overall, 2) each level alone of each class variable, 3) if you have more than 2 class variables you'll also get the combinations of 2, or 3 or what ever smaller number of variables and 4) the combinations of the all levels of all the class variables.

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13
proc means data=Z_score2;
var X1 X2 X3 X4 X5 Z;
by Costat SIC1_4;
output out=results;
run;

PROC EXPORT DATA= results 
            OUTFILE= "\\path\results.xlsx" 
            DBMS=EXCEL REPLACE;
RUN;

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
  • 8 replies
  • 10351 views
  • 4 likes
  • 4 in conversation