Help using Base SAS procedures

Why the 'RUN' statement must be taken out

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 131
Accepted Solution

Why the 'RUN' statement must be taken out

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?


Accepted Solutions
Solution
‎01-04-2012 12:09 PM
PROC Star
Posts: 7,356

Why the 'RUN' statement must be taken out

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


All Replies
PROC Star
Posts: 7,356

Re: Why the 'RUN' statement must be taken out

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=

Super User
Super User
Posts: 6,497

Why the 'RUN' statement must be taken out

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.

Frequent Contributor
Posts: 131

Why the 'RUN' statement must be taken out

Thanks a lot art297 and Tom.

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

PROC Star
Posts: 7,356

Why the 'RUN' statement must be taken out

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;

Frequent Contributor
Posts: 131

Why the 'RUN' statement must be taken out

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.

Frequent Contributor
Posts: 131

Why the 'RUN' statement must be taken out

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

Solution
‎01-04-2012 12:09 PM
PROC Star
Posts: 7,356

Why the 'RUN' statement must be taken out

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

Frequent Contributor
Posts: 131

Why the 'RUN' statement must be taken out

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 199 views
  • 6 likes
  • 3 in conversation