Is it possible to include submitted syntax or even output of log file when ODS into a PDF using SAS?
For instance, give this simple code:
ods pdf file = "c:\temp\myPDF.pdf";
proc reg data = mydata;
model y = x;
run;
ods pdf close;
I can get the regression output and accompanying graph fine. But is it possible to incorporate into PDF the enclosed command like this?
proc reg data = mydata;
model y = x;
run;
It is, but it requires a couple of hoops. Luckily, you could wrap this into macros to clean up your code.
Create a temporary fileref to hold your log.
Start your PDF and output the log to the fileref.
Write code.
Stop writing log to fileref.
Print file contents to PDF using ODF TEXT=
Hope this helps
filename x temp;
ods pdf file="c:\temp\temp.pdf";
title "Cost of Power";
options source;
proc printto log=x;
run;
proc reg data=sashelp.cars;
model msrp = horsepower;
run;
quit;
proc printto;run;
title;
ods pdf startpage=now; /*Force a new page in the PDF*/
data _null_;
infile x;
input;
call execute("ods text='LOG: "||_infile_||"';");
run;
ods pdf close;
filename x ;
Related
I am creating a RTF file using SAS ODS. When I add a text using "ODS TEXT", the column headers of a table are not repeating in next page but comes only at the start of the table.
When I remove the "ODS TEXT", I get columns names in all pages. Since I need a text above the table (not in header/title), can you suggest a solution?
data chk;
set sashelp.class;
output; output;
run;
ods rtf file = "xx\check.rtf";
ods escapechar = '^';
title " ";
ods text="ods text";
proc report nowd data=chk ;
run;
ods rtf close;
I'm wondering if it's possible to save the query results to csv? Without creating views.
I have a large table but need only 2 columns from there to process with python then. Maybe someone can help with it?
Here are three ways
ODS
SQL query can be output to an ODS CSV destination. This approach encompasses the widest possibilities of querying.
ods csv file='c:\temp\query-results.csv';
proc sql;
select name, age
from sashelp.class
where name like 'J%'
;
quit;
ods csv close;
EXPORT Procedure
Where clause can be applied using kept columns of 'a large table' (data=)
proc export
data = sashelp.class(
keep=name age
where = (
name like 'J%'
)
)
replace
file = 'c:\temp\class-subset.csv'
dbms = csv
;
run;
DATA _null_
Where statement can be applied using any columns of 'a large table' (SET). The PUT statement manages which columns are output.
data _null_;
set sashelp.class;
where name like 'J%';
file 'c:\temp\subset-per-datastep.csv' dlm=',' dsd;
if _n_ = 1 then put 'name,age';
put name age;
run;
I think you can use ods to create file with results, for example:
ods csv file="C:\test.csv" options(delimiter=';');
proc sql;
select * from sashelp.class;
quit;
ods csv close;
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;
I have a stored Process which returns an Excel as Download (with long loading time because of big data). This works correct, but after download it leaves a blank page. So i want to put some html text in the blank page, best would be a loading icon before, and a "finished" information after downloading the excel. But when i use a ods html after/Before the excel output, instead of downloading the excel it puts the excel as HTML-TextOutput as well, is there a way to do both outputs in one Process?
Code Sample:
/* something like:*/
ods html body=_webout;
data _null_;
file _webout;
put '<img src="loading.gif" />';
run;
ods html close;
/*here is the Exceloutput which i use at the moment without htmloutput*/
%let RV=%sysfunc(appsrv_header(Content-type, application/vnd.ms-excel));
%let RV=%sysfunc(appsrv_header(Content-disposition,%str(attachment; filename=myExcel.xls )));
ods tagsets.excelxp file=_webout options(embedded_titles='yes' embedded_footnotes='yes'
sheet_interval='none' sheet_name='Result') ;
PROC PRINT DATA=AUSDRUCK UNIFORM NOOBS LABEL;
OPTIONS DATE NUMBER;
TITLE1"myExcel ";
VAR var1 var2 var3 var4 var5;
RUN;
ods tagsets.excelxp close;
/*and then something like:*/
ods html body=_webout;
data _null_;
file _webout;
put 'Excel download finished successfull';
run;
ods html close;
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.