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;
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'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";
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.
I have some sas code:
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, but i need the results window not open.
I have tried noprint in the proc freq but this stops the code executing at all.
Any ideas?
Thanks in advance!!
ods results off;
ods results on;
above worked for me. Stopped the results tab opening.
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="©from.\...." 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="©from.\...." 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;