Sas PROC EXPORT xlsx without named ranges - sas

how Can I use PROC Export and obtain excel file without named ranges?
I've got something like this now:
proc export
data=WORK.INFO
dbms=xlsx
outfile=&fn
replace;
sheet="INFO";
putnames=no;
run;

Assuming you need output without headers, PROC REPORT is the way to go.
ods _all_ close;
ods excel file=&fn. options(sheet_name="INFO");
title;
proc report data=WORK.INFO nowd noheader;
run;
ods excel close;
/* Then Re-enable whatever ods destinations you want active */

Related

SAS regression result output to excel in one sheet

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;

SAS- how to PROC EXPORT multiple PROC FREQ created by a macro?

I have a macro which looks like this:
%macro mac_name (st, en=);
%do j=1 %to &en.;
%let k=%eval(&j.+1);
proc freq data=data_name;
tables status&j. * status&k. / nocol norow nopercent missing;
run;
%end;
%mend;
%mac_name (st=1, en=%sysfunc(week(%sysfunc(today()), u)));
The output produces multiple proc freq tables with the same title.
I need this output put into a excel spreadsheet. Ideally all proc freqs in one sheet, one above the other or separate sheets.
Is this possible?
Thanks in advance!!!
The easiest way to do this is to use ODS EXCEL, if you have SAS 9.4.
ods excel file="yourfilename.xlsx";
proc freq data=sashelp.class;
tables age;
run;
proc freq data=sashelp.class;
tables sex;
run;
ods excel close;
You have options for whether they're all on one sheet or separate sheets. You can use ODS TAGSETS.EXCELXP if you have an earlier version of SAS, though they're less "true excel" files. You can also make CSV files or various other things with ODS.
In your case you'd put the opening ODS EXCEL line before the first call of the macro (doesn't have to precede the definition of the macro) and then the ODS EXCEL CLOSE line after the last call.

export datasets into multiple sheets of one excel file in sas

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

SAS- Supress Results view on some, but not all, proc print ods outputs

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.

Suppressing HTML output in SAS

I'm trying to suppress HTML output and get PROC PRINT to output only to CSV, but ODS HTML Close doesn't seem to work.
My code is:
ODS HTML close;
ODS CSV file="\\..output folder..\filename.csv";
proc print data=test;
run;
ODS CSV close;
ODS HTML;
Your approach seems a bit odd, why resort to ods csv?
SAS has a proc export procedure:
proc export data=test outfile="\\..output folder..\filename.csv" dbms=CSV replace;
run;
You can further configure it to have a different delimiter, no headers etc.: http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000393174.htm
EDIT
In reply to your comment: i see two ways around the issues that keep you from trying proc export.
The first approach is setting the validvarname to ANY, which gives you great liberty in choosing variable names. E.g.:
options validvarname=ANY;
data test;
'Column Header Text I Want'n=1; output;
'Column Header Text I Want'n=5; output;
run;
proc export data=test outfile="\\..output folder..\filename.csv" dbms=CSV replace;
run;
Personally, i'm not a fan of the above approach, since i find that it leads to harder-to-read code when you no longer have some naming rules for variables.
A second approach - which i prefer - is to label the variable with the text you want it to have and put the label option on your proc export. E.g.:
data test;
label variable_name='Column Header Text I want';
variable_name=1; output;
variable_name=5; output;
run;
proc export data=test outfile="\\..output folder..\filename.csv" dbms=CSV replace LABEL;
run;
Note that there is a small distinction in the output: the first approach will not put quotes around your column names while the second approach will do that.
Finally, while doing some extra reading myself, i stumbled across this, which may be of help to you as well: http://www.sascommunity.org/wiki/Create_a_CSV_file_without_column_names/headers_in_row_1#DATA_NULL_with_a_PUT_statement.2C_all_fields_quoted
I'm been trying all day and finally got it for me. What I wanted suppress from the results viewer is just below here (and the end of a macro). The results I wanted in the results viewer and now called in a separate macro at the end...
Brubumski
ODS HTML close; * bsk;
ods results off; * bsk;
ods csvall file="&file1";
proc print data=tr_outds noobs; run;
ods csvall close; * bsk;
ods results on; * bsk;
ODS HTML; * bsk;
%OdsOn1(outds,outds2,tr_outds, file1, file2); * bsk;
%mend process_input_data_10_10;
%macro OdsOn1(outds,outds2,tr_outds, file1, file2);
proc freq data=outds;tables Group_nm/missing;run;
proc freq data=outds2;tables case_id/missing;run;
proc print data=tr_outds(obs=10) noobs; run;* bsk;
ods csvall file="&file2";
proc print data=cases noobs; run;
ods csvall close;
%mend OdsOn1;
Ah, I've found out the problem. The results window will still display HTML output which will really slow the program down as ODS HTML CLOSE seems to only affect ouput to a specific file, not the results window.
In order to stop that, I should have used ODS RESULTS OFF; instead.
ODS RESULTS OFF;
ODS CSV file="\\..output folder..\filename.csv";
proc print data=test;
run;
ODS CSV close;
EDIT: It seems that ODS RESULTS cannot be turned on and off at will to cause only certain PROC PRINT statements to generate outputs. This is really annoying for me, so I'm going with Shorack's PROC EXPORT methods.