BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bncoxuk
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

View solution in original post

8 REPLIES 8
art297
Opal | Level 21

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=

Tom
Super User Tom
Super User

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.

bncoxuk
Obsidian | Level 7

Thanks a lot art297 and Tom.

A very silly mistake. I will need to learn macro.

art297
Opal | Level 21

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;

bncoxuk
Obsidian | Level 7

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.

bncoxuk
Obsidian | Level 7

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

art297
Opal | Level 21

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

bncoxuk
Obsidian | Level 7

Yes, the code worked perfectly. Everytime I received good help and learned from you. Thanks a lot!!!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 8 replies
  • 1100 views
  • 6 likes
  • 3 in conversation