Hello, I've created an excel file using ods.
The file contains few of proc tabulate, each one is displayed after the other one .( see screenshot)
I want to display two proc tabulate next to each other , how can I do that?
thank you for your help
As far as I know, ODS EXCEL does not have the capability of displaying tables next to one another.
Known:
ODS EXCEL OPTIONS(START_AT="<column>,<row>");
Based on these two facts you can create a work around as follows:
Example:
ods _all_ close;
ods noresults;
filename xlsout 'my report.xlsx';
filename script 'merge sheets.ps1';
ods excel file=xlsout;
* first table in first worksheet;
proc tabulate data=sashelp.cars;
class type origin;
table type,origin/nocellmerge;
run;
ods excel options (start_at="6,1");
* second table in second worksheet.
* right of the where the first table is;
proc tabulate data=sashelp.cars;
class drivetrain origin;
table drivetrain,origin/nocellmerge;
run;
ods excel close;
* write powershell script and run it;
data _null_;
file script;
length outline $256;
input;
outline = resolve(_infile_);
put outline;
datalines4;
$xl = new-object -c excel.application
$xl.DisplayAlerts = $false # prevent 'are you sure' dialogs
$wb = $xl.Workbooks.Open("%sysfunc(pathname(xlsout))") # open SAS generated Excel
$ws1 = $wb.Worksheets(1)
$ws2 = $wb.Worksheets(2)
$row = $ws2.UsedRange.Cells(1,1).Row # determine where paste will go
$col = $ws2.UsedRange.Cells(1,1).Column
$ws2.UsedRange.Copy() # copy output in 2nd sheet to clipboard
$ws1.Cells($row,$col).PasteSpecial(-4104) # paste into 1st sheet at proper location
$ws1.Cells(1,1).Select() # deselect paste range
$ws2.Delete() # remove second sheet
$wb.Save() # save without 'are you sure' dialog
$xl.quit()
;;;;
options xwait xsync xmin;
%sysexec powershell -file "%sysfunc(pathname(ps1))";
filename script;
filename xlsout;
ods results;
Final saved Excel
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.