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()
Related
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 need to create sum of 4 variables multiple times each time with new set of variables. For e.g. A1=sum(a1,a2,a3,a4),B1=sum(b1,b2,b3,b4) & so on. So , I am trying to write a macro that will help me do it easily. Following is the code:
%macro SUM2(VAR1,var2,var3,VAR4);
data Subs_60_new;
set Subs_60;
substr(&var1,1,10)=sum(&var1,&var2,&var3,&var4);
run;
%mend sum2;
options mprint mlogic;sum2(ADDITIONAL_INFO_Q1,ADDITIONAL_INFO_Q2,ADDITIONAL_INFO_Q3,ADDITIONAL_INFO_Q4);
I am using SAS EG for the same & when I run the macro I get the following note:
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
& obviously when I try to execute the macro it throws an error.
Can some one help me out?
when calling a macro, you need to precede the macro name with a % symbol, eg as follows:
%macro SUM2(VAR1,var2,var3,VAR4);
data Subs_60_new;
set Subs_60;
substr(&var1,1,10)=sum(&var1,&var2,&var3,&var4);
run;
%mend sum2;
options mprint mlogic;
%sum2(ADDITIONAL_INFO_Q1,ADDITIONAL_INFO_Q2,ADDITIONAL_INFO_Q3,ADDITIONAL_INFO_Q4);
The NOTE is harmless. It is ERRORs and WARNINGs in general that you should be concerned with.
I'd point out that this will probably still throw an error, as you are trying to replace characters in a variable (&var1) that appears as though it should contain a numeric field (being part of a sum function). Given your description of what you are trying to achieve, I'd suggest adding the new variable name as another macro parameter - as follows:
%macro SUM2(VAR1,var2,var3,VAR4,varname);
data Subs_60_new;
set Subs_60;
&varname=sum(&var1,&var2,&var3,&var4);
run;
%mend sum2;
options mprint mlogic;
%sum2(ADDITIONAL_INFO_Q1,ADDITIONAL_INFO_Q2
,ADDITIONAL_INFO_Q3,ADDITIONAL_INFO_Q4
,MyNewVariable);
I have a macro variable, &myvar, but it won't resolve when I try to put it in a data step variable. Why won't it, and what can I do to fix this?
%let myvar=Hello, world;
data _null_;
x='&myvar.';
put x=;
run;
Macro variables in SAS won't resolve when they are in single quotes, '&myvar'. They need to be in double quotes, "&myvar", in order to resolve properly.
If you need to have single quotes and a resolved macro variable, you have a few options, but the simplest is:
%str(%'&myvar.%')
The %' inside of %str will place a single quote character (or apostrophe) in the text string by itself without causing it to be quoted.
data _null_;
x="%str(%'&myvar.%')";
put x=;
run;
or
%let myvar2 = %str(%'&myvar.%');
In SAS 9.4M6 or higher version, you can use %tslit() to achieve the same function.
%let myvar=Hello, world;
data _null_;
x=%tslit(%superq(myvar));
put x=;
run;
%put %tslit(%superq(myvar));
x=Hello, world
'Hello, world'
This is a macro pre-defined in SAS. Here is the documentation about it:
https://documentation.sas.com/?docsetId=lebaseutilref&docsetTarget=n1phgnraoodvpln1bm941n44yq7q.htm&docsetVersion=9.4&locale=en
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.
I have a problem with SAS 9.2.
I'm writing a simple macro which creates dataset and name it according to the variables submitted and some other words/letters/signs, for example
%macro example(var1,var2);
data &var1 || '_word_' || &var2;
a=1;
run;
%mend;
Can anyone help?
Pipes are only for strings within SAS, not within SAS macro. So don't use them here.
SAS Macro does not interpret quotes as indicating a string, it will just read them, so leave out the quotes.
If you want to concatenate elements in macro, you just need to write them appended to each other.
To make clear where the macro variable name ends, append a dot.
This should work:
%macro example(var1,var2);
data &var1._word_&var2.;
a=1;
run;
%mend;