I'm trying to print out a table to an email destination and then put some custom comments at the end. When I try and run the below code I get the message:
ERROR: File is in use, .
My code is:
filename mymail email content_type="text/html"
to=("myemail#myemail.com")
from=("myemail#myemail.com")
subject="My Report";
ods html3 body=mymail style=sasweb;
proc print data=sashelp.class noobs;
run;
data _null_;
file mymail ;
put "I want this to appear at the bottom of the email.";
run;
ods html3 close;
filename mymail clear;
I've tried googling for help but the search terms are so vague it's tough to narrow it down to this specific problem. Thanks for the help.
EDIT: Just to clarify - I want all the results in the body of the email. I don't want the results sent as an attachment. Also, if you comment out just the data step in the above code, the email works fine.
I wasn't able to test these two approaches in an actual email, but they did avoid the (replicable) Error: File is in use message..
filename mymail "C:/temp/test.html";
ods html3 body=mymail style=sasweb;
proc print data=sashelp.class noobs;
footnote "Approach 1: I want this to appear at the bottom of the email.";
run;
data _null_;
file print ;
put "Approach 2: I also want this to appear at the bottom of the email.";
run;
ods html3 close;
filename mymail clear;
The change is to use the file print reference in the data step. According to the SAS Documentation:
PRINT is a reserved fileref that directs the output that is produced by any PUT statements to the same file as the output that is produced by SAS procedures.
Its not clear to me whether you actually needed the data step to do any data processing, versus just printing text. I recently had a similar challenge, but my focus was on simply printing text, so you can use the ODS text function:
ODS HTML3 text="Approach 3: Use the ODS TEXT function to put text anywhere.";
Depending upon your html destination, you can use css or html tags to govern font, size, alignment, etc. I'll guess you're using html3 for outlook compatibility, so css tags won't work.
Related
I'm using SAS v9.4, running a connection via DDE to Word 2010.
I would like to copy and paste an entire table from onw word document to another. The table is bookmarked "IDX" and I am able to select the table using the following code:
options noxsync noxwait xmin;
filename sas2word dde 'winword|system';
data _null_;
file sas2word;
put '[EditGoTo.Destination = "IDX"]';
put '[TableSelectTable]';
run;
I have tried put '[ctrl+c]';, put '[copy]';, put '[TableCopy]';, put '[SelectionCopy]'; but nothing seems to work, and the code crashes. Does anyone know the syntax to copy the entire table, then paste it into a different document?
Here is SAS 9.4M4 sample code that use experimental ODS WORD destination to create two Word documents, and copies a table from one to the other. YMMV, and you probably have addition work regarding issues such a table wrapping and anchoring.
filename one "c:\temp\one.docx";
filename two "c:\temp\two.docx";
ods _all_ close;
title; footnote;
options nocenter nonumber nodate;
ods word file=one;
proc print data=sashelp.class (obs=5);
proc print data=sashelp.cars (obs=5);
proc print data=sashelp.demographics (obs=5);
proc print data=sashelp.class (obs=5);
run;
ods word close;
ods word file=two;
proc print data=sashelp.cars (obs=10);
run;
ods word close;
* start WORD;
options noxsync noxwait xmin;
%sysexec start "Yada yada yada" winword;
%let rc = %sysfunc(sleep(5,1));
%put NOTE: &=rc;
* define channel for sending commands;
filename word_cmd dde 'winword|system';
* put will send the commands to WORD;
data _null_;
file word_cmd;
cmd = cats ( "[FileOpen.Name=", quote(trim(pathname("One"))), "]");
put cmd;
put '[EditBookmark name:="IDX3", goto:=1]';
put '[NextObject]';
put '[GoToNextSection]';
put '[TableSelectTable]';
put '[EditCopy]';
cmd = cats ( "[FileOpen.Name=", quote(trim(pathname("Two"))), "]");
put cmd;
put '[Selection.Goto(wdGotoLine, wdGotoLast)]';
put '[EditPaste]';
run;
The Word command ListCommands will create a document containing a table of all the Word Commands and active key mappings.
data _null_;
file word_cmd;
put '[ListCommands]';
run;
The list goes on for 10 pages in Word 2016. Word commands are also invokable from dde connections. Unfortunately ListCommands lists a descriptive command name, and not the command that dde actually requires, and does not actually list all commands. The WordMVP site (https://wordmvp.com) has assembled a list - "Word for Windows commands"
Word has a built-in command ListCommands, which produces a table of all the Word commands with their current key and menu assignments. However, it does not list the commands using their actual names; nor does it include descriptions of what the commands actually do.
…
WordCmndsPDF.zip contains a list of all interceptable Word commands (Word 97 and above), using their correct English names
Another reference for Word commands can be found at "Visual Basic Equivalents for WordBasic Commands", 6/13/2014.
A SAS conference paper search for "WORD DDE" will also provide additional material.
I'm attempting to dynamically display text within an email by using a %macro in the place of the dynamic text. This was working, but after adding a few additional lines of text to my email, it stopped working. So, I'm unsure of what is causing the actual issue. Reverting back to where I was when it was working no longer works.
My macro I'm calling:
%macro PrintStuff(arrayOfThings);
%local i next_element;
%do i=1 %to %sysfunc(countw(&arrayOfThings));
%let next_element = %scan(&arrayOfThings, &i);
%DO;
%PUT "&next_element info is as follows:";
%PUT "some text here";
%PUT "some text there";
%PUT "text all over!!!";
%PUT "Do you even text?";
%END;
%end;
%mend PrintStuff;
email code:
DATA _null_;
File mailFile;
PUT "This is email text. This shows up fine in the email";
%PrintStuff(&someArray);
PUT "This closes the email, and this shows up fine in the email when it is received!"
RUN;
I've tried a few different things here. I've tried ONLY having %PrintStuff(&myArrayOrList) in the email. I've tried it with and without a closing ; semicolon. I'm not sure where this went wrong.
The log appears this way after the code has run successfully:
50 DATA _null_;
51 File outmail;
52 PUT "This is email text. This shows up fine in the email";
53
54 %PrintStuff(&someArray)
"ResolvedElementName info is as follows:"
"some text here"
"some text there"
"some text all over!!!"
"Do you even text?"
55
56 PUT "This closes the email, and this shows up fine in the email when it is received!";
57 RUN;
It worked, and now it doesn't, and I'm not sure how it could have worked before now. Any advice would be greatly appreciated!!! Thanks in advance!
Put in data step writes into output table/file (i.e. outmail in your example), %put in your macro writes into log. Try replacing %put in the macro by put - it will add those 5 lines to your data step.
I am new at SAS and I have this SAS macro, it will send me a email when the process has finished, but it is not working properly.
In the log just say macros's name like it work but the email is not coming to my inbox.
%macro mailing()
data _null_;
start = %eval(%sysfunc(today(), mmddyy5)-1);
endd = %eval(%sysfunc(today(), mmddyy5)-8);
run;
FILENAME mail EMAIL
SUBJECT=" corporative subject"
FROM='corporativemail#server.com'
SENDER='corporativemail#server.com'
TO=("mymail#server.com")
DATA _NULL_;
FILE mail;
PUT "Hi,";
PUT "here goes &start. - $endd. ";
PUT "Best Regards,";
PUT "me";
RUN;
%mend
%macro mailing()
By the way, I do not know if those date variables are properly defined
The issue is that you are not actually calling the macro. You only use %macro when defining a macro.
To call it, simply precede the macro name with a % symbol, as follows:
%mailing()
I am new to SAS and I am trying create a batch file through a SAS program. The code is below:
data new;
enddate=date();
getdate=date()+1;
flname1=compress("d:\temp\file"||year(enddate)||put(month(enddate),z2.)||
put(day(enddate),z2.)||".txt");
begdate=enddate-&days;
dtline1=compbl(compress("00:00_"||put(begdate,mmddyy10.))||" "||
compress("00:00_"||put(getdate,mmddyy10.)));
file 'h:\programs\daily_file';
put 'LOGIN abc xyz';
put 'FILE(C:\temp\list.txt)
dtline1 "script.pl("flname1")";
put 'LOGOUT';
Script.pl is a perl script and in the resulting batch file, there is an extra space after flname1. It prints something like this:
script.pl(d:\temp\file_date ).
I don't want the this extra space after date. What can I do?
The easiest way to get that to work properly is simply to put the entire command (script.pl(filename)) into a single variable, then put that variable.
You can also use +(-1) in put to move the line pointer back one, if it's consistently off by one (though most of the time that's not needed).
put "script.pl(" flname1 +(-1) ")";
It really looks like you are working too hard to create string variables before writing to the file. You should be able to write what you want just using the features of the PUT statement. It is not clear from the question what format you want the file to have, but I think this code mimics your program.
%let days=7 ;
data new;
enddate=date();
getdate=date()+1;
begdate=enddate-&days;
file 'h:\programs\daily_file';
put 'LOGIN abc xyz'
/ 'FILE(C:\temp\list.txt) 00:00_' begdate mmddyy10.
' 00:00_' getdate mmddyy10.
' script.pl(d:\temp\file' enddate yymmddn8. '.txt)'
/ 'LOGOUT'
;
run;
and it produces:
LOGIN abc xyz
FILE(C:\temp\list.txt) 00:00_08/14/2015 00:00_08/22/2015 script.pl(d:\temp\file20150821.txt)
LOGOUT
I want to get the file size of a csv file in AIX and using following X and Call System Command to do. The problem is I cant get the "File Size" in a macro variable which I will be using later in the program.
data _null_;
call system('du -g p_bhj_c_hh100uk01po1.csv');
call symput('space','X du -g p_bhj_c_hh100uk01po1.csv');
%put &space;
run;
WARNING: Apparent symbolic reference SPACE not resolved.
First, the SYMPUT subroutine you call does not work like you are trying to use it (ala Perl). I recommend reading the documentation on it.
The error you get on the SPACE macro is because it is inside the DATA Step. Macros "write" SAS code for you, so it &SPACE macro is trying to be resolved BEFORE the DATA Step executes.
Here is a code example to do what you are looking for:
data _null_;
rc = filename("ref","e:\temp\reg.pdf");
fid = fopen("ref");
infonum = foptnum(fid);
do i=1 to infonum;
infoname = foptname(fid,i);
infoval=finfo(fid,infoname);
put infoname= infoval=;
end;
close = fclose(fid);
run;
/*In Windows, attribute is "File Size (bytes)"*/
data _null_;
rc = filename("ref","e:\temp\reg.pdf");
fid = fopen("ref");
size=finfo(fid,"File Size (bytes)");
call symput("size",size);
close = fclose(fid);
run;
%put &size;
The File Size attribute may be different in AIX. Run the first part to see all the attributes available. Then modify the second accordingly. Likewise, you will need to add the call to produce the file like you are already doing.