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

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";

Related

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;

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.

SAS-How to NOPRINT in ODS CSV

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.

SAS-Writing Multiple Tables to one XLSX Workbook w/ 2 tables per sheet

I am new to SAS and am having some issues exporting data. I have written a macro to generate some summary tables based on a certain ID. The macro creates two tables for each ID identified in a particular proc sql query. I can write out the last two tables but it overwrites all tables. I was wondering if there is a way to generate one sheet, containing the two summary tables, for each ID identified in my query. Below is the code I have to date for exporting data:
%macro output(x);
ods tagsets.excelxp file="W:\user\test.xls" options(sheet_interval='none');
proc print data=prov_&x;
run;
proc print data=prov_revcd_&x;
run;
ods tagsets.excelxp close;
%mend;
/*Run a loop for each IDcode. Each code will enter the document generation loop*/
%macro loopit(mylist);
%let else=;
%let n = %sysfunc(countw(&mylist)); /*let n=number of codes in the list*/
data
%do I=1 %to &n;
%let val = %scan(&mylist,&I); /*Let val= the ith code in the list*/
%end;
%do j=1 %to &n;
%let val = %scan(&mylist,&j); /*Let val= the jth code in the list*/
/*Run the macro loop to generate the required tables*/
%runtab(&val);
%output&val);
%end;
run;
%mend;
/*Run the macro loop over the list of significant procedure code values*/
%loopit(&varlist);
Any help for correcting this issue would be greatly appreciated! Thanks!
I would rewrite %output like so.
%macro output(x);
ods tagsets.excelxp options(sheet_interval='none' sheet_name="&x");
proc print data=prov_&x;
run;
proc print data=prov_revcd_&x;
run;
%mend;
Then as Reeza suggests put the original ods tagsets.excelxp file= ... and close outside the whole macro.
ods tagsets.excelxp file="c:\temp\test.xlsx";
%loopit(&varlist)
ods tagsets.excelxp close;
If you use PROC EXPORT, that does allow apending to a workbook without this step (and no ODS at al).
%macro output(x);
proc export data=prov_&x outfile="c:\temp\test.xlsx" dbms=excel replace;
sheet="&x._prov";
run;
%mend;
However, this only allows one dataset per sheet - so either you append them together first as a single dataset, or you use 2 sheets in this solution.
Move the ods tagsets.excelxp file= and ods tagsets.excelxp close to outside of the macro otherwise you're recreating the file each time.
You may want to explicitly name the sheets as well.

Generate proc import logs for multiple files to a pdf

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;