BookmarkSubscribeRSS Feed
BruceBrad
Lapis Lazuli | Level 10

I would like to email the contents of the current program editor window. Is this possible? (This is to send jobs to a remote processing system that only receives jobs via email).

9 REPLIES 9
KarlK
Fluorite | Level 6

In the DMS Enhanced Editor, if you do File-->Send Mail, a new message window opens with your current program attached as a txt file (at least in Windows). Does that work for you?

If, on the other hand, your program needs to be the actual body of the e-mail message instead of an attachment, I don't think there's a point-and-click way to do that. You could, of course, save your program, then write another program which reads your program back in as text, and sends it using "filename email".

HTH

Karl

BruceBrad
Lapis Lazuli | Level 10

Unfortunately the program needs to be in the body of the email. Saving the file then reading it back as text sounds feasible. Can someone give me pointers on how to start such a program running and how to automate display commands such as saving the editor window to a temporary file? I know SAS macro but don't have any experience automating the editor.

KarlK
Fluorite | Level 6

I confess I'm a little confused. Your original posting indicated you had a program in the program editor. How did it get there? If you typed it in, or copy/pasted from another source, then just hit the "Save" button or type "flsvlast" into the command line. If it's already saved somewhere with a ".sas" extension, then you don't need to open it up in the editor at all. A ".sas" file is plain text. You just need a program to open it as text, read it in, and "put" the contents to the output destination with "filename email".

There's no reason I can think of for "automating the editor". Am I missing something?

Karl

BruceBrad
Lapis Lazuli | Level 10

Karl, the scenario is basically as you describe. I have the program open in the editor and am testing it on my local machine. When it is ready to go, I want to type something on the command line (or choose a menu item or button) which will then start a program which

1) finds out which sas file I currently have open

2) saves it (sounds like flsvlast is the command I need for this)

3) runs another SAS program which reads the file back in and sends it to email.

So step 1 requires some 'automating'.

I'm also pondering how to do step 3) because I can't use MAPI (I'm using SAS 64 and Office 32) and I don't seem to have access to a simple SMTP server - my university SMTP server requires STARTTLS.

KarlK
Fluorite | Level 6

I'm still curious as to how the program gets into the editor, but anyway:

1) assuming you're using the enhanced editor, the environment variables SAS_EXECFILENAME and SAS_EXECFILEPATH contain the name and the full path respectively of the currently running program. You'd use the %sysget() function to return those values to your program. I realize that what you really want is the fully-qualified name of the program in the editor window, but I'm not sure how to get that--again, because the program got into the window somehow, so I don't know how you wouldn't now that it's name already.

2) yeah maybe. On the other hand, do you need to save the file at all? Once you have it working in test mode, why not just write a little wrapper program that you copy the contents of the window into. It would turn your program into data, input it basically as a dataset in WORK, and then output it to filename email. Something like;

data myProgram;

input program_line $ 1-80; /* big enough for your longest program line */

datalines;

<paste your  program here>

;

run;

then read myProgram into your email program. It seems to me that you're making it too complicated, but there are pieces of the puzzle I don't know.

3) I might recommend making this step a new thread to get help from somebody better able than I to handle the many details of e-mailing from SAS. I do it all the time, but it took me a while to find the right combination of EMAILHOST, EMAILAUTHPROTOCOL and EMAILSYS that reliably works with my SMTP server. Sorry I can't be more help.

BruceBrad
Lapis Lazuli | Level 10

Thanks Karl

Well yes, I do know the name of the program in the editor, but I'm working with several different ones and get easily confused 🙂

Re 2), that is an interesting idea, but it is not really any better than cutting and pasting into my email program. I'll do some more exploring on 3) and maybe put up a separate thread.

Cheers

Bruce.

Tom
Super User Tom
Super User

I find it much easier to automate the original program editor (instead of the "enhanced" editor).  You can create command line macros to automate the steps.  But it would still be difficult to prevent it from losing the name of the file that SAS thinks you are editing (not that I trust SAS to remember the name of the file I am editing as it has a nasty habit of thinking I am editing the file that I just pulled in to copy some code from).

Example:

%macro xx /cmd ;

gsub 'filename code temp;' ; file code ; gsub 'data _null_; infile code; input; list; run; filename code clear' ;

%mend xx;

You could replace the data _null_ step with code to copy the file to proper email address.  You could even map the command macro to a function key or icon on the toolbar.

Sudhakar_A
Calcite | Level 5

If you save the contents of the enhanced editor we can send the contents as an attachment to the mail. If yes pls reply i will give the code send mail as an attachment.

bbenbaruch
Quartz | Level 8

I don't do anything as elegant as creating a macro.  To preserve the formatting and color coding of the Enhanced Editor, I simply copy the part of the code that I want to include in my email and paste it into MS Word then copy it from MS Word and paste it into my email.  I use Outlook but I assume that most current email software will handle the text similarly.

Clunky and inelegant -- but simple and relatively fast.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1400 views
  • 3 likes
  • 5 in conversation