New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

Hi,

 

I have a SAS extract that I would like to send as an excel file.

I want to send this to outlook.

 

My trail:

I exported the file to my local c: drive and then write the below code so SAS picks the file and attaches it as an excel and sends it.

I am getting the error :

ERROR: Error opening attachment file C:/Name of folder/Name of excelfile.xlsx.
ERROR: Physical file does not exist, /sas94apps/prod94config/Lev1/user/C:/Folder name/Excel name.xlsx.

 

Is there a way I can send this?

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

Hello,

 

Please provide the code how your attaching the file to email.

 

Here is a sample code:

filename outbox email
      from='abc@abc.com'
	  to='abc@abc.com' 
	  type='text/html'
	  subject='Test Mail'
	  attach=("/user/test.xlsx" content_type="excel");
	  
ods html body=outbox rs=none style=Htmlblue;

proc odstext;
p 'Hello,';
p ' Please find the attachment';
p 'Thank You';
title;
run;
ods html close;

Also, it looks like your SAS is on Unix/Linux and your trying to attach a file that is in your local machine. SAS doesn't have communication for your local drive, so you may need to move the file to Unix or to a location mount between both.

Thanks,
Suryakiran

View solution in original post

15 REPLIES 15
SuryaKiran
Meteorite | Level 14

Hello,

 

Please provide the code how your attaching the file to email.

 

Here is a sample code:

filename outbox email
      from='abc@abc.com'
	  to='abc@abc.com' 
	  type='text/html'
	  subject='Test Mail'
	  attach=("/user/test.xlsx" content_type="excel");
	  
ods html body=outbox rs=none style=Htmlblue;

proc odstext;
p 'Hello,';
p ' Please find the attachment';
p 'Thank You';
title;
run;
ods html close;

Also, it looks like your SAS is on Unix/Linux and your trying to attach a file that is in your local machine. SAS doesn't have communication for your local drive, so you may need to move the file to Unix or to a location mount between both.

Thanks,
Suryakiran
new_sas_user_4
Quartz | Level 8

Below is the code I am using and getting the erros mentioned in my question

filename outmail email to=("new_Sas_user@xx.ca")
cc=("new_Sas_user@xx.ca")
replyto=("new_Sas_user@xx.ca")
subject=("Data")
attach=("C:/Folder Name/File_Name.xlsx" content_type="application/xlsx");
run;

DATA _NULL_;
FILE outmail;
PUT "Hello";
PUT "Plesae find Report as an attachment";
PUT "Thank you";
RUN;

SuryaKiran
Meteorite | Level 14

Please check your path, give a valid path name what SAS can read from. Is your SAS running on Unix/Linux or Windows local. Windows has '\' and linux/unix has '/', your are mixing them.

Thanks,
Suryakiran
new_sas_user_4
Quartz | Level 8

I am running SAS on a windows laptop.

SuryaKiran
Meteorite | Level 14

What SAS Application your connected to? SAS Studio, SAS Enterprise Guide, PC SAS ?

 

Your using Windows laptop doesn't mean that your running SAS that was installed in your laptop. Your log shows --->  /sas94apps/prod94config/Lev1/user which I suspect that your SAS is installed on a server (unix/Linux) and your connecting to it through the application your using (I guess it might be SAS Enterprise Guide ). 

 

Are you using SAS EG (Enterprise Guide) ?

Thanks,
Suryakiran
new_sas_user_4
Quartz | Level 8

yes, I am using SAS Enterprise Guide.

SuryaKiran
Meteorite | Level 14

 

proc setinit;
run;

 

 

Run this and check the log for operating system or check the location C:\Program Files\SASHome\SASFoundation\9.4 for SAS to see if SAS is installed in your local machine. If you have SAS installed in local machine then check whether your running on server "LOCAL" in SAS EG. Some people have multiple servers listed (View>Servers List).

 

Untitled.png

If you don't have SAS installed locally then you have to copy your file to server, check this link for copy files option in SAS EG. Once the files are moved to serve then you have to use the server path. (Under server>Files>several folders here). Find a location where you have access on server to save your work.

Thanks,
Suryakiran
new_sas_user_4
Quartz | Level 8

SAS is installed on my local machine but I am not running on the LOCAL server

I am running on 

Selected server: BIApp_User

 

My extracts are produced under the work library.

 

I want to send the excel version of the extract 

If I specify /sas94apps/prod94config/Lev1/BIApp_USER/Work.my_extract_file_name.xlsx

 

I get the error: Physical file does not exist, /sas94apps/prod94config/Lev1/BIApp_USER/Work.my_extract_file_name.xlsx"
content_type="application\xlsx.

 

Any thoughts on how can I resolve this?

SuryaKiran
Meteorite | Level 14

When it says physical file doesn't exists, you need to make sure the path your providing really exists. 

 

Try this trick to find the physical path for the file:

 

In SAS EG, can you see your file (.xlsx) when you navigate through "Files"

 

Capture.PNG

 

If yes, drag and drop in the project flow and by default it will try to import. In the import wizard you can actually file the right physical path for that particular file. If by default import wizard doesn't open then go to file>import data

Thanks,
Suryakiran
new_sas_user_4
Quartz | Level 8

I see files under my WORK library (but they are sas formatted).

I want to send the file as an excel.

SuryaKiran
Meteorite | Level 14

Then you have to create the excel files first in a location where you have access.

 

proc export 
  data=work.<your dataset name here>
  dbms=xlsx 
  outfile="/user/mypath/export_test.xlsx" 
  replace;
run;
Thanks,
Suryakiran
new_sas_user_4
Quartz | Level 8

Thanks Suryakiran!!

I am now able to send the file to my BIApp_User folder under servers.

 

 

Using the below code:

FILENAME Mailbox EMAIL 'myemail@xxxx.ca'
Subject='Test Mail message'
ATTACH="/users/mypath/my_filename.xlsx" ; /*I am using the same folder location I used to export the file*/
run;

/*subject line of the mail*/
DATA _NULL_;
FILE Mailbox;
PUT "Hello"; /*mail body*/
PUT "This is a message from the DATA step";
RUN;

 

I am receiving a message in my outlook mailbox 

(Hello 

This is a message from the DATA step.)

 

There is an excel attachment name my_filename but when I open it it says ""

"We found a problem with some content in 'myfilename.xlsx' . Do you want to try to recover as much as we can? If you trust the source of this workbook, click Yes "

 

How can I resolve this?

SuryaKiran
Meteorite | Level 14

Please check my initial reply that give an example code to send the excel file, you require content_type='excel'

attach=("/user/test.xlsx" content_type="excel")

 

Thanks,
Suryakiran
new_sas_user_4
Quartz | Level 8

Thanks a ton 🙂

Finallyyyyy able to do it !!! 

Thanks again!!!!!!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 15 replies
  • 24382 views
  • 3 likes
  • 2 in conversation