DATA Step, Macro, Functions and more

Need to send report to a shared drive instead of e mail

Accepted Solution Solved
Reply
Contributor
Posts: 64
Accepted Solution

Need to send report to a shared drive instead of e mail

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;

Accepted Solutions
Solution
‎12-04-2016 07:27 AM
Trusted Advisor
Posts: 1,554

Re: Need to send report to a shared drive instead of e mail

Posted in reply to ambadi007

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.




View solution in original post


All Replies
Super User
Super User
Posts: 7,942

Re: Need to send report to a shared drive instead of e mail

Posted in reply to ambadi007

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.

Trusted Advisor
Posts: 1,554

Re: Need to send report to a shared drive instead of e mail

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.

Contributor
Posts: 64

Re: Need to send report to a shared drive instead of e mail

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

Solution
‎12-04-2016 07:27 AM
Trusted Advisor
Posts: 1,554

Re: Need to send report to a shared drive instead of e mail

Posted in reply to ambadi007

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.




Contributor
Posts: 64

Re: Need to send report to a shared drive instead of e mail

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 

 

Trusted Advisor
Posts: 1,554

Re: Need to send report to a shared drive instead of e mail

[ Edited ]
Posted in reply to ambadi007

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 ?

 

Contributor
Posts: 64

Re: Need to send report to a shared drive instead of e mail

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 .

Trusted Advisor
Posts: 1,554

Re: Need to send report to a shared drive instead of e mail

Posted in reply to ambadi007

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:

https://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/viewer.htm#p0v0ijxl1k6d4b...

 

see examples 3 and 6.

Trusted Advisor
Posts: 1,554

Re: Need to send report to a shared drive instead of e mail

there is some problem with the forum editor.
the red part is : ' ' || put(&date, &format) ||
Contributor
Posts: 64

Re: Need to send report to a shared drive instead of e mail

src=&path || &name || '.xlsx';

src2 = &path || &name || '.xls';

path=&rptpath, name=&rptname . This &rptpath and &rptname is the output for the first %let macro.

 

Super User
Posts: 11,343

Re: Need to send report to a shared drive instead of e mail

Posted in reply to ambadi007

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 392 views
  • 2 likes
  • 4 in conversation