Please have a look at the following code:
FILENAME newemail EMAIL TO="xxx@xxx.com" SENDER="xx" SUBJECT="Place to go";
%MACRO sender;
%DO i=1 %TO 5;
Timer=SLEEP(2); /*Wait for 20 mins*/
DATA _NULL_;
SET work.place(WHERE=(min=minute(timepart(datetime()))));
FILE newemail;
PUT "Now go to: " place;
RUN;
%END;
FILENAME newemail CLEAR;
%MEND;
%sender
Because of the RUN statement, SAS produced the following error message:
9 Timer=SLEEP(2);
-----
180
MPRINT(SENDER): Timer=SLEEP(2);
ERROR 180-322: Statement is not valid or it is used out of proper order.
If the RUN statement is removed, then it worked perfectly. Why this happened?
I'm not able to test sending emails, thus I can only guess. I think you can still simplify it, but use a macro. e.g.:
%MACRO sendit;
%DO i=1 %TO 5;
FILENAME newemail EMAIL TO="xxx@xxx.com" SENDER="xx" SUBJECT="Place to go";
DATA _NULL_;
SET work.place(firstobs=&i. obs=&i.);
FILE newemail;
PUT "Now go to: " place;
Timer=SLEEP(2); /*Wait for 2 seconds*/
RUN;
FILENAME newemail CLEAR;
%END;
%MEND;
%sendit
I'm not sure why, but I wasn't able to use the macro name sender, so I changed it to sendit
The error isn't because of the run statement .. it is because you are trying to assign a variable outside of a datastep. Try removing the Timer=
Try adding a RUN; statement before you call the macro and you will get the error message again.
Turn on the MPRINT option and you will see what code the macro is generating and the issue will be more obvious.
You have an assignment statement BEFORE your DATA step starts. By removing the RUN statement SAS is happily using that statement into the DATA step from the previous iteration of you macro do loop.
Thanks a lot art297 and Tom.
A very silly mistake. I will need to learn macro.
Plus, for what you are doing, I don't think you need either a macro or the matching of a timestamp. Couldn't you just use something like:
FILENAME newemail EMAIL TO="atabachneck@gmail.com" SENDER="art297@rogers.com" SUBJECT="Place to go";
data place;
input place $;
cards;
C
B
D
E
A
;
DATA _NULL_;
SET work.place;
timer=SLEEP(2); /*Wait for 2 seconds*/
FILE newemail;
PUT "Now go to: " place;
RUN;
FILENAME newemail CLEAR;
Hi art297, thanks for your code. My task is to send 5 emails separately, with one place each time. Your code simply sends all 5 places in a single email.
art297,
you code is more simple than the macro used. If I want to send one place at a time, how should I adapt your code? The task is to send 5 emails separately, with one place each time
I'm not able to test sending emails, thus I can only guess. I think you can still simplify it, but use a macro. e.g.:
%MACRO sendit;
%DO i=1 %TO 5;
FILENAME newemail EMAIL TO="xxx@xxx.com" SENDER="xx" SUBJECT="Place to go";
DATA _NULL_;
SET work.place(firstobs=&i. obs=&i.);
FILE newemail;
PUT "Now go to: " place;
Timer=SLEEP(2); /*Wait for 2 seconds*/
RUN;
FILENAME newemail CLEAR;
%END;
%MEND;
%sendit
I'm not sure why, but I wasn't able to use the macro name sender, so I changed it to sendit
Yes, the code worked perfectly. Everytime I received good help and learned from you. Thanks a lot!!!
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.