BookmarkSubscribeRSS Feed
CharlesFowler72
Obsidian | Level 7

Hi guys,

 

so in my work set up when im using sas I cannot accesses files directly from file paths (e.g. C:\documents\Summary.pdf) meaning I cannot open or save anything down.

 

What I am trying to achieve is to send a data set "D_Jumpers" as an excel attachment in an email.

 

At the moment the code I have is...

 

FILENAME mail EMAIL TO='charles.fowler@company.co.uk'

SUBJECT="D Jumpers" CONTENT_TYPE="text/html";

ODS HTML BODY=mail;
PROC PRINT DATA=D_Jumpers;
RUN;
ODS HTML CLOSE;

 

 

 

this puts the table in the body of the email. But I cant find anything online which puts the dataset in an excel as an attachment without referencing a "C:\filepath" anywhere.

 

any help? something tells me I will be able to do a slight modification on the above code that will work but not sure what it is.

 

thank you in advanced.

 

21 REPLIES 21
ballardw
Super User

@CharlesFowler72 wrote:

Hi guys,

 

so in my work set up when im using sas I cannot accesses files directly from file paths (e.g. C:\documents\Summary.pdf) meaning I cannot open or save anything down.

 

What I am trying to achieve is to send a data set "D_Jumpers" as an excel attachment in an email.

 

At the moment the code I have is...

 

FILENAME mail EMAIL TO='charles.fowler@company.co.uk'

SUBJECT="D Jumpers" CONTENT_TYPE="text/html";

ODS HTML BODY=mail;
PROC PRINT DATA=D_Jumpers;
RUN;
ODS HTML CLOSE;

 

 

 

this puts the table in the body of the email. But I cant find anything online which puts the dataset in an excel as an attachment without referencing a "C:\filepath" anywhere.

 

any help? something tells me I will be able to do a slight modification on the above code that will work but not sure what it is.

 

thank you in advanced.

 


Can you describe why you "cannot accesses files directly from file paths"? It might help to show some code and messages from the loq when attempting to do so. Perhaps it is a specific location issue.

Can you create libraries anywhere?

CharlesFowler72
Obsidian | Level 7

essentially its because it is blocked by the company I work for. So for example If I were trying to create a PDF (which ive tried before) using the code

 

ods pdf file="c:\temp\Alfred.pdf";
 proc print data=D_Jumpers;
 title "D Jumpers";
 run;
 ods pdf close;
 title;

then the error would be "ERROR: Insufficient authorization to access /grasp/sas92/config/sascompute/Lev1/SASApp/c:\temp\Alfred.pdf.". I've spoken to the IT department and have been told it cannot be done.

 

yeah we have plenty of library space to save the output data set.

Tom
Super User Tom
Super User

@CharlesFowler72 wrote:

essentially its because it is blocked by the company I work for. So for example If I were trying to create a PDF (which ive tried before) using the code

 

ods pdf file="c:\temp\Alfred.pdf";
 proc print data=D_Jumpers;
 title "D Jumpers";
 run;
 ods pdf close;
 title;

then the error would be "ERROR: Insufficient authorization to access /grasp/sas92/config/sascompute/Lev1/SASApp/c:\temp\Alfred.pdf.". I've spoken to the IT department and have been told it cannot be done.

 

yeah we have plenty of library space to save the output data set.


Your SAS code is running on Unix.  You cannot use Windows syntax to reference files when running on Unix.  You could create a shared network location that could be access by both the Unix server and your  Windows machine(s).  But the syntax for the path will most likely look different.  /grasp/data/temp/Alfred.pdf vs \\grasp_server\data\temp\Alfred.pdf 

CharlesFowler72
Obsidian | Level 7

yes that sounds right. It has been explained to me in the past, a while back now. I work for a pretty big company and trying to change the system is essentially not an option. I need to just try and work round these problems and find alternative ways of doing things.

 

So this is my problem in trying to send a dataset as an excel attachment. All examples I find online use filepaths which just isn't an option for me.

Kurt_Bremser
Super User

How did you create the Excel in the first place?

If you use filename excel or ods excel, the resulting file will aready be stored on the server for filename email to pick it up.

CharlesFowler72
Obsidian | Level 7

I haven't created it. Its just a temp data step at the moment "D_Jumpers". Am I just missing something really simple?

Kurt_Bremser
Super User

@CharlesFowler72 wrote:

I haven't created it. Its just a temp data step at the moment "D_Jumpers". Am I just missing something really simple?


It can't have appeared out of thin air (unless you're Harry Potter, of course). So I have to ask again: how was it created, and how did it end up on your C: drive?

CharlesFowler72
Obsidian | Level 7

At the moment there is no excel file. There is just a dataset in my work library. I need that to be an excel file attached to an email with the problem that I don't have access to a drive to save the excel file down. 🙂 It could be an impossible task.   

Tom
Super User Tom
Super User

@CharlesFowler72 wrote:

yes that sounds right. It has been explained to me in the past, a while back now. I work for a pretty big company and trying to change the system is essentially not an option. I need to just try and work round these problems and find alternative ways of doing things.

 

So this is my problem in trying to send a dataset as an excel attachment. All examples I find online use filepaths which just isn't an option for me.


You you just trying to find a path on your Unix box where you can create a file that you want to attach to an email?

Why just just write the file into the WORK directory that SAS is using?

%let path=%sysfunc(pathname(work));
CharlesFowler72
Obsidian | Level 7

that would work. So then what code do I need to use to send the dataset in the work directory as an excel file attachment?

Tom
Super User Tom
Super User

It seems pretty clear in the documentation.  Or here is an old article about it.

http://www2.sas.com/proceedings/forum2008/038-2008.pdf

So you make an XLSX file some how.

%let path=%sysfunc(pathname(work));

* Make the EXCEL file ;
libname out xlsx "&path/myexcel.xlsx";
data out.report;
   set sashelp.class;
run;

Then when you are sending the email you use the ATTACH= option tell it to attach that file.

FILENAME MailBox EMAIL ATTACH="&path/myexcel.xlsx";
CharlesFowler72
Obsidian | Level 7
When I run the Libname line I get an error "ERROR: The XLSX engine cannot be found."
andreas_lds
Jade | Level 19

Which SAS-version are you using? Executing

%put &=SYSVLONG;

prints the version number to the log.

CharlesFowler72
Obsidian | Level 7
im using SAS Enterprise Guide 4.3

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 21 replies
  • 2731 views
  • 0 likes
  • 5 in conversation