Generate proc import logs for multiple files to a pdf - sas

I have written a SAS macro that imports all the excel files in a folder and it works. What I want to do next is - send the proc import logs or results for all the excel files to a single pdf. My SAS code looks like this:
%macro readxls (copyfrom=);
---
---
---
%do i=1 %to $count_files;
ods listing close;
ods pdf file='pathname\report_import.pdf';
proc import datafile="&copyfrom.\...." out=copyto.... DBMS=xlsx replace;
getnames=yes;
run;
ods pdf close;
ods listing;
%end;
%mend readxls;
For some reason, no pdf file gets generated. And the SAS log says, "NOTE: Writing ODS PDF output to DISK destination "pathname\report_import.pdf", printer "PDF"

You cannot redirect the log directly to an ODS output destination. The import procedure has no output that is send to an ODS destination.
What you can do is redirect the log to a textfile using PROC PRINTTO. Next you can import the file using PROC DOCUMENT and write it to an ODS output destination using the replay function.
filename pdflog 'pathname\report_import.pdf';
filename tmplog 'pathname\report_import.txt';
proc printto log=tmplog;run;
%macro readxls (copyfrom=);
%do i=1 %to $count_files;
proc import datafile="&copyfrom.\...." out=copyto.... DBMS=xlsx replace;
getnames=yes;
run;
%end;
%mend readxls;
%readxls(copyfrom=...);
proc printto;run;
proc document name=pdflog(write);
import textfile=tmplog to logfile;
run;
ods listing close;
ods pdf file=pdflog notoc;
replay;
run;
ods pdf close;
quit;
ods listing close;

Related

Write multiple SAS datasets into one Excel sheet

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.

Sas PROC EXPORT xlsx without named ranges

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 */

SAS Management Console - The file is empty and can not be sent

I've scheduled some sas code using SAS Management Console.
However the job ends with an error: The file is empty and can not be sent.
The code which exports proc freqs to a file is as follows:
%let output_Date = %sysfunc(today(),yymmddn8.);
ods results off;
ods csv file="path/file.csv";
%macro movem (st, en=);
%do j=1 %to &en.;
%let k=%eval(&j.+1);
proc freq data=dataname;
tables status&j. * status&k. / nocol norow nopercent missing ;
run;
%end;
%mend;
%movem (st=1, en=%sysfunc(week(%sysfunc(today()), u)));
ods csv close;
ods results on;
I haven't used ods before and was wondering whether this causes the issue/error?
In Enterprise guide the code seems to give me no error.
Thanks in advance!
In your code
ods csv file="path/file.csv";
path is a placeholder, it should be replaced with actual path, e.g. /sas/projects/mypath,
or you can assign it to a macro variable:
%let path=/sas/projects/mypath;
Then your ods statement will look like:
ods csv file="&path/file.csv";

SAS - how to stop results tab opening in sas using code.

I have the below code:
ods _all_ close;
ods csv file="filename.csv"
%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)));
ods csv close;
which works fine.
The only problem is i don't want the results tab to open up, and this has to be done from within the code as i am to schedule the job.
Any ideas?
Thanks in advance!
If you're not running it in batch, I'd recommend using the ods noresults statement. I've posted a simple, reproducible example using Sashelp.Cars below. This was tested in windows SAS 9.4 only.
ods _all_ close;
ods noresults;
ods csv file="filename.csv";
proc print data=Sashelp.Cars;
run;
ods csv close;
ods _all_ close;

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