I want to output my SAS regression result into excel.
The code is:
proc import datafile = 'cmds.csv'
out = Work.cmds
dbms = CSV;
run;
ODS TAGSETS.EXCELXP
file="dt.xls";
STYLE = STATISTICAL;
proc sort data=Work.Cmds out=Work.Cmds;
by year;
run;
proc reg data=Work.Cmds outest=want tableout;
by year;
model Investment = Size Growth_New Leverage complex Deficit pc_income_NEW Density/hcc adjrsq ;
ods output parameterestimates=want2;
run;
ODS TAGSETS.EXCELXP CLOSE;
Although it successfully generates the excel file, it contains many sheets. I want to generate all things in one sheet. How can I do?
There are options within the tagsets, in specific sheet_interval. To have all go to one page, set the sheet interval option to none.
ODS TAGSETS.EXCELXP file="dt.xls" STYLE = STATISTICAL options (sheet_interval='none');
However, TAGSETS.EXCELXP generates an XML file, not an Excel file. If you have SAS 9.4 TS1M4+ then I would recommend ODS EXCEL instead.
ods excel file="dt.xlsx" style=statistical options (sheet_interval = 'none');
List of all options for ODS TAGSETS.EXCELXP is here:
https://support.sas.com/rnd/base/ods/odsmarkup/excelxp_help.html
Full example that will generate a single tab:
ods tagsets.excelxp file='C:\_localdata\demo.xls' options(sheet_interval='none');
proc sort data=sashelp.cars out=cars;
by origin;
run;
proc reg data=cars outest=demo tableout;
by origin;
model mpg_city = mpg_highway invoice cylinders;
ods output parameterEstimates=want;
run;
ods tagsets.excelxp close;
Related
I am using SAS enterprise guide 7.15.
I want to export several datasets into multiple excel sheets (multiple tables in every sheet).
I'm using ODS and even though i'm setting sheet_interval="none", after two tables it breaks the page, and shoves the next tables to another excel sheet.
this is an example to my code, here it's exporting 2 tables, later I want to add 20 tables more in the same sheet:
%macro table_1;
proc report data=table_1 out=sheet_1 headline split='#' spacing=1 nowd missing
style(summary)={font_weight=bold}
columns
segment
diff
cnt_old
cnt_new
;
compute before _page_/style=[font_size=3 font_weight=bold foreground=white background=Dark Blue];
line "table 1";
line ' ';
line 'Number of Customers';
endcomp;
compute after;
endcomp
run;
%mend table_1;
%macro table_3;
proc report data=table_3 out=sheet_1 headline split='#' spacing=1 nowd missing
style(summary)={font_weight=bold}
columns
FinalRiskRating
diff
cnt_old
cnt_new;
compute before _page_/style=[font_size=3 font_weight=bold foreground=white background=Dark Blue];
line "table 3";
endcomp;
compute after;
endcomp
run;
%mend table_3;
%table_1; %table_3;
%let shk = table_1 + table_3;
ods path work.temptemp(update) sasuser.templat(update) sashelp.tmplmst(read);
ods path show;
Options mprint mlogic symbolgen nobyline;
ods listing close;
%macro b;
%do i=1 %to 2;
%let mshk=%scan(&shk., &i.,+);
/*ods tagsets.excelxp options(SHEET_INTERVAL='NONE' PAGEBREAK="NO" sheet_name="sheet1" ABSOLUTE_COLUMN_WIDTH='8' AUTOFIT_HEIGHT='yes' embed_titles_once = 'yes' embedded_titles='yes');*/
ods tagsets.excelxp options(sheet_interval="none" sheet_name="sheet1" ABSOLUTE_COLUMN_WIDTH='8' AUTOFIT_HEIGHT='yes' embed_titles_once = 'yes' embedded_titles='yes');
%&mshk.;
%end;
%mend b;
ods tagsets.excelxp file="&reportlocation";
%b;
ods tagsets.excelxp close;
ods _all_ close;
;
My suspicion is because you don't specify sheet_interval='none' on the initial ods tagsets.excelxp.
Like yours, the first example has this problem:
ods tagsets.excelxp file="h:\temp\test.xls";
ods tagsets.excelxp options(sheet_interval='none');
proc print data=sashelp.class;
run;
ods tagsets.excelxp options(sheet_interval='none');
proc print data=sashelp.class;
run;
ods tagsets.excelxp close;
But this works as expected:
ods tagsets.excelxp options(sheet_interval='none') file="h:\temp\test.xls";
proc print data=sashelp.class;
run;
proc print data=sashelp.class;
run;
ods tagsets.excelxp close;
Interestingly, if you remove the second one, it still works - so it's not exactly that it's not on the first line, but rather it's the new options statement. I guess that resets it somehow. But in your case there's really no reason not to put any of those details on the initial ods tagsets.excelxp statement.
ODS EXCEL doesn't work that way, it always goes all on one sheet. I'd recommend using that, if you can, in any event.
I have to export some data in the format of two tables per row, with multiple rows. So far I have got as far as building a report with multiple tables stacked on top of each other, but with only one per row by using multiple proc report statements in a code statement as so:
proc report data = mydata; title 'My Title:'; run;
proc report data = mydata; title 'My Title:'; run;
proc report data = mydata; title 'My Title:'; run;
What do I need to add/amend so that I get two tables per row in my report?
Thanks
Some destinations support this directly in the ODS statement; like ODS PDF.
ods pdf file="test.pdf" columns=2 ;
proc print data=sashelp.class;
run;
proc freq data=sashelp.class;
tables age;
run;
ods pdf close;
However, HTML doesn't. For those you'll want to use ODS LAYOUT.
ods html file="test.html";
ods layout gridded
columns=2;
ods region;
proc print data=sashelp.class;
run;
ods region;
proc freq data=sashelp.class;
tables age;
run;
ods layout end;
ods html close;
See the ODS Layout Tip Sheet for more details.
ODS LAYOUT won't work with ODS EXCEL, sadly. You can use this macro to do something similar, if you prefer, or perhaps use PROC DOCUMENT to get the tables together, but I'm not sure exactly how that would work.
If you want more than one table in each column, then you can either have one ODS REGION per table (they'll end up being alternated l-r-l-r) or you can just add more to the two ODS REGIONs here if you don't need them to be gridded properly.
IE:
ods html file="test.html";
ods layout gridded
columns=2;
ods region;
proc print data=sashelp.class;
run;
ods region;
proc freq data=sashelp.class;
tables age;
run;
ods layout end;
ods html close;
Those just have two columns with 2 tables in each column, but they're not aligned.
ods html file="test.html";
ods layout gridded
columns=2;
ods region;
proc print data=sashelp.class;
run;
ods region;
proc freq data=sashelp.class;
tables age;
run;
ods region;
proc print data=sashelp.cars;
run;
ods region;
proc freq data=sashelp.cars;
tables origin;
run;
ods layout end;
ods html close;
This has a proper grid layout.
I resolved this in the end by tweaking the above as so:
ods layout gridded columns=2 rows=2;
ods region;
proc print data=sashelp.class;
run;
ods region;
proc freq data=sashelp.class;
tables age;
run;
ods region;
proc print data=sashelp.cars;
run;
ods region;
proc freq data=sashelp.cars;
tables origin;
run;
ods layout end;
Obviously, rows and columns will change depending on your needs. This produces a SAS report, that I then exported as a step in the project as a HTML file.
Thanks
I am trying to use hidden_rows in place of hidden_columns, but it doesn't work.
Any help will be appreciated.
ods tagsets.excelxp file="spacing.xls" style=statistical
options( hidden_columns='1,2,3');
proc print data=sashelp.class;
run;
ods tagsets.excelxp close;
tagsets.excelxp does not have an option hidden_rows. The tagset documentation can be written to the log window using this code:
ods tagsets.excelxp file="sandbox.xml" options (doc='all');
ods tagsets.excelxp close;
In what context are you trying to hide rows in the Proc REPORT output ? detail lines, group lines, summary lines ?
I'm use this code
proc export data=goldsheet_invalid outfile="C:\Documents and Settings\sasadm\Desktop\gold.xls" dbms=xls replace;
sheet="gold";
run;
proc export data=platinumsheet_invalid outfile="C:\Documents and Settings\sasadm\Desktop\gold.xls" dbms=xls replace;
sheet="platinum";
run;
proc export data=titaniumsheet_invalid outfile="C:\Documents and Settings\sasadm\Desktop\gold.xls" dbms=xls replace;
sheet="titanium";
run;
Error:Statement is not valid or it is used out of proper order
Note:- already try dbms=xlsx or dbms=EXCELCS but not work
Instead of using a PROC EXPORT this can be accomplished with older versions of SAS using ODS (Output Delivery System) statements. Going this route is not as clean as the PROC EXPORT but if all you want is to get the data from these data sets to a single Excel workbook and have the results of each proc statement on a different worksheet this will do it.
In this case the code to accomplish what you are looking for would be:
ods tagsets.excelxp file='C:\temp\gold.xml' options(sheet_name = 'Gold' sheet_interval='proc');
proc print data=goldsheet_invalid;
run;
ods tagsets.excelxp options(sheet_name = 'Platinum');
proc print data=platinumsheet_invalid;
run;
ods tagsets.excelxp options(sheet_name = 'Titanium');
proc print data=titaniumsheet_invalid;
run;
ods tagsets.excelxp close;
You will notice that the file extension created is XML, this is a necessity. When you load the file in Excel is would appear as expected and feel free to update the file extension from there.
More details about SAS and ODS can be found at: https://support.sas.com/rnd/base/ods/odsmarkup/TipSheet_ods_xl_xp.pdf
I want to be able to print all of my reports to external files but only display a select few in the results viewer. In the below example I want reportA and reportB to be displayed AND printed (file.xls) but reportC to be printed to a separate file (file2.csv) and not displayed in the results viewer. Any ideas?
ods msoffice2k file="/file/file.xls";
proc print data=reportA;
run;
proc print data=reportB
run;
ods msoffice2k close;
ods csvall file="/file/file2.csv";
proc print data=reportC;
run;
ods csvall close;
You can also use ODS EXCLUDE and ODS SELECT to target specific destinations.
For example, ods html select none; will turn off the HTML destination temporarily, but not actually close it - it just won't get any results for a while. You can then use ods html select all; to turn it back on.
You can also use ods html exclude all; to do the same thing and then turn it back on with ods html exclude none;.
With either statement, you can also use a where statement in the ods select/exclude to filter to only affect one specific part of an output. See the documentation for more details.
Close the list output which is the default. OR the HTML if that is the default results window in your system. Re-open the output after the file is created.
ods msoffice2k file="/file/file.xls";
proc print data=reportA;
run;
proc print data=reportB
run;
ods msoffice2k close;
ods listing close;
ods html close;
ods csvall file="/file/file2.csv";
proc print data=reportC;
run;
ods csvall close;
ods listing;
ods html;
I actually found a better solution through using the proc export feature for suppressing display of the csv output.
ods msoffice2k file="/file/file.xls";
proc print data=reportA;
run;
proc print data=reportB
run;
ods msoffice2k close;
proc export data=reportC
outfile="/file/file2.csv"
dbms=dlm
replace;
delimiter=",";
run;
Thanks for the help #Reeza I'll keep those settings in mind for future projects.