@@nickspencer wrote:
I am looking to use ods and include var in proc print. How do I include sheet name and replace options in ods since I haven’t used it before?
ODS EXCEL gives you a lot of control over output into Excel so it's certainly worth learning.
If you have specific "How To" usage questions then just Google them. There are quite a few solutions out there.
One "downside" with ODS EXCEL: It will always fully re-create the file and you can't update, delete or add a sheet in place.
The following code shows how to define a specific sheet name. Replace is not required as it's always gonna be a full create of the whole workbook.
ods excel file='c:\temp\test.xlsx'
options(autofilter='all' sheet_name='mysheet');
proc print
data=sashelp.class(obs=5);
var Age Name Sex Weight Height;
run;
ods excel close;
ods excel file="filename.Xlsx";
Proc print data=have; /* or proc report */
Var a b c d; /* set the variable order here */
run;
ods excel close;
There's a few ways, Option 3 is probably the simplest since the order only matters for presentation.
Option 1: RETAIN statement before the SET statement.
data class;
retain Age Sex Name Weight Height;
set sashelp.class;
run;
Option 2: PROC SQL with FEEDBACK option and manual reorder
proc sql feedback;
create table class as
select * from sashelp.class;
quit;
Copy the code from the log, reorder the variables and then re-run it.
Option 3: Use ODS Excel to PROC PRINT the results and manually control the order there.
ods excel file='/folders/myfolders/demo.xlsx';
proc print data=sashelp.class noobs label;
var Name Age Sex Weight Height;
run;
ods excel close;
@nickspencer wrote:
I have a sas dateset which had to be exported in an excel sheet. But the excel output should have columns in a specific order. What can be the best way to order the variables in an specific order?
How are performing the Excel output?
@nickspencer wrote:
I am looking to use ods and include var in proc print. How do I include sheet name and replace options in ods since I haven’t used it before?
Ok, then use PROC EXPORT. The steps have been explained above.
@@nickspencer wrote:
I am looking to use ods and include var in proc print. How do I include sheet name and replace options in ods since I haven’t used it before?
ODS EXCEL gives you a lot of control over output into Excel so it's certainly worth learning.
If you have specific "How To" usage questions then just Google them. There are quite a few solutions out there.
One "downside" with ODS EXCEL: It will always fully re-create the file and you can't update, delete or add a sheet in place.
The following code shows how to define a specific sheet name. Replace is not required as it's always gonna be a full create of the whole workbook.
ods excel file='c:\temp\test.xlsx'
options(autofilter='all' sheet_name='mysheet');
proc print
data=sashelp.class(obs=5);
var Age Name Sex Weight Height;
run;
ods excel close;
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.