Hi Experts,
I was using e mail to sent my reports to the users. Now a new system is in place and I need to send the report to one shared drive instead of mail. Here I cant do a simple export because I have particular templates for different reports. I was using one e mail macro to pick the reports from a folder and sent email. I am attching that macro with this. Please let me know if there is any way to sent it to a folder insted of using mail .Thanks.Manesh
%macro emailreport(path=, name=, ext=, date=, format=, to=, cc=, msg=, sig=, attach=);
FILENAME mail EMAIL 'nul' ;
DATA _NULL_;
FILE mail ;
subject = &name;
tolist = tranwrd(trim('(' || quote(&to) || ')'), ';', '" "');
cclist = tranwrd(trim('(' || quote(&cc) || ')'), ';', '" "');
msg=&msg;
sig=&sig;
datestr = put(&date, &format);
attachment = &path || &name || ' ' || datestr || '.' || &ext;
put '!EM_TO!' tolist;
put '!EM_CC!' cclist;
put '!EM_SUBJECT!' subject;
if (&attach) then
put '!EM_ATTACH!' attachment;
if (missing(msg) = 0) then
put msg;
if (missing(sig) = 0) then
put sig;
/*put '!EM_SEND!';*/
run;
%mend emailreport;
I assume you want both copies of the reportnames - the one with the datestring and the other in the shared drive without it.
When you say 58 reportname - do you mean 58 different files, each with its name.
Can you write to the shared drive from SAS ?
If yes then run next code for each of the 58 report names:
filename in "&pat.&name.&datestring..&ext"; filename out "SharedDriveDirectory.&name..&ext";
data _NULL_;
infile in truncover;
input _infile_ $;
file out;
put _infile_;
run;
you can do it with a macro, with just one argumnet: &name
as in:
%macro copy_file(namex);filename in "&path.&namex.&datestring..&ext"; filename out "SharedDriveDirectory.&namex..&ext"; /* adatpt shared folder name */
data _NULL_;
infile in truncover;
input _infile_ $;
file out;
put _infile_;
run;
%mend copy_file;
%copy_file(report1);
%copy_file(report2);
etc.
Well,
"Here I cant do a simple export because I have particular templates for different reports"
Not sure what you mean here. Templates are a SAS item used at report creation and have nothing to do with where you store output files, so not sure why this would be an issue.
You should simply be able to put the url to the output path in the creation of your outputs - this is the simple standard method of creating output files.
Create you report file in its final name - either directly on the shared drive or copy the file created to shared drive
and use the email - without attachment - just to acknowledge the user(s) that the file is ready.
Hi Shmuel,
Yes I can create the report in some other folder and copy that to the shared drive as you suggested , I have one doubt over here while copying the respective file I dont need the date string with the report (normally I create the report with date string )the report in the
The template name will be 58 reportname. We load the data in to the template and create the report named below
And the report name will 58 reportname 2016-11-18
And while sending the report to shared drive I dont need the date string it should be static . I cant create with out date string While creating the report.because If i create the report with out date string the template will overwrite. Please give me some sollution
I assume you want both copies of the reportnames - the one with the datestring and the other in the shared drive without it.
When you say 58 reportname - do you mean 58 different files, each with its name.
Can you write to the shared drive from SAS ?
If yes then run next code for each of the 58 report names:
filename in "&pat.&name.&datestring..&ext"; filename out "SharedDriveDirectory.&name..&ext";
data _NULL_;
infile in truncover;
input _infile_ $;
file out;
put _infile_;
run;
you can do it with a macro, with just one argumnet: &name
as in:
%macro copy_file(namex);filename in "&path.&namex.&datestring..&ext"; filename out "SharedDriveDirectory.&namex..&ext"; /* adatpt shared folder name */
data _NULL_;
infile in truncover;
input _infile_ $;
file out;
put _infile_;
run;
%mend copy_file;
%copy_file(report1);
%copy_file(report2);
etc.
Hi ,
I have tried the code but not able to achieve the result. your assumption was correct I export the report to one drive . The drive will have a template for the reports and I use the attached macro to do the export of the report. Its not 56 reports that is report number , all the report will be having a report number. Now my client need to send one copy of the report to another folder with out the date string. I have tried with X command and the cold you have provided and was not able to get it. I attaching the export report macro It will be a
%let rptpath= path;
%let rptname='56 rptname';
%let rptdate=today();
%let rptdatefmt = YYMMDDd10.;
%macro exportreport(path=, name=, date=, format=, data=);
data _NULL_;
src=&path || &name || '.xlsx';
src2 = &path || &name || '.xls';
dest = &path || &name || ' ' || put(&date, &format) || '.xlsx';
dest2 = &path || &name || ' ' || put(&date, &format) || '.xls';
if (fileexist(src)) then
do;
call system('copy ' || quote(src) || ' ' || quote(dest));
call symput('_exportreportpathname', dest);
end;
else if (fileexist(src2)) then
do;
call system('copy ' || quote(src2) || ' ' || quote(dest2));
call symput('_exportreportpathname', dest2);
end;
run;
%exportfile(pathname=&_exportreportpathname., data=&data);
%mend exportreport;
%exportreport(path=&rptpath, name=&rptname, date=&rptdate, format=&rptdatefmt, data=FINAL_OUT);
great help if I can get a similar macro to sent export the report with out date string to another folder.thanks>manesh
Your lines:
dest = &path || &name || ' ' || put(&date, &format) || '.xlsx';
dest2 = &path || &name || ' ' || put(&date, &format) || '.xls';
. =============================
Is DEST2 - the shared drive to have the report without the date ?
If so - you should just remove the red part ?!
===
What are src, src2 files - that is not output report of your first macro ?! where is the date ?
No dest2 is for if the sheet xls format.This code is only for exporting the report in to one folder and Now I need to send it from that folder to the shared drive with out the date string. Its a different server from there my users can access the report.Previoulsy I use to send this throu e mail , we are now trying to get rid of the e mail part .
If I understand, ypur general flow is:
- read input file(s) and create report file
- copy the report file to destination-1 on same server, with a name including date
- copy the report file to destination-2 on other server, without the date
use similar code to copy files adapting (changing) the target file refence:
While writing to the same server the referece is like:
- D:\pathname\filename.ext - on windows or
- /pathname/filename - on unix or linux
to write on remote server -
- you need permission to write to the specific folder
- your reference to the file shoul be like:
filename dest3 ftp 'c:\remote\test.dat' host='winnt.pc' user='bbailey' pass='xxxx' recfm=v;
for more details link to:
see examples 3 and 6.
src=&path || &name || '.xlsx';
src2 = &path || &name || '.xls';
path=&rptpath, name=&rptname . This &rptpath and &rptname is the output for the first %let macro.
One of the generic approaches to wrap ANY output generator in an ODS "sandwich" to provide destination and file type. Trivial example:
ODS PDF file="c:\myreportfolder\myreport.pdf";
proc print data=mydatafile;
run;
Ods pdf close;
sends the output of the proc print or any other procedures between the ODS PDF file and ODS PDF Close statements to a PDF document in the specified location.
There are many different ODS types and the different file types have additional options. The file location must be one that your SAS installation has write permissions to so the path may need some tweaking if you use a SAS server as the path would be relative to the server.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: