DATA Step, Macro, Functions and more

SAS Code issues

Reply
Regular Contributor
Posts: 152

SAS Code issues

Hello experts,

For the code below, if "error" variable in the following work.merge dataset loaded into hash table has values that contain many special characters like [,./;'etc]. How do I make the following code works? (please just focus on error variable which is highlighted in blue, that is where I get the error in the log)

%macro Email(email=,suite=,reference=,error=,time=,abortcode=,);
FILENAME Mailbox EMAIL "&email"
Subject= "";
DATA _NULL_;
FILE Mailbox;
PUT "Hello";

PUT "Error message: &error";
PUT "Run time: &time";
PUT "Abortcode: &abortcode";

RUN;
%mend;

  data _null_;
    length email $200 suite $200 reference $200 errormsg $200 time $200 abortcode $200;
    if _n_=1 then do;
      declare hash myhash(dataset: 'work.merge',ordered:'a'); /* sort order is ascending */
       declare hiter iter('myhash');
       myhash.definekey('suite'); /* define a key */
       myhash.definedata('Email','Suite','Reference','errormsg','time','abortcode'); /* getting the columns */
       myhash.definedone(); /* finish the definitions */
      call missing(email, suite,reference,errormsg,time,abortcode); /* avoid uninitialized variable notes (miss in the dataset not in hash)*/
    end;
    /* Iterate through the hash object and output data values */
    rc = iter.first();
    do while (rc = 0);
      call execute('%Email(email='||Email||',suite='||Suite||',reference='||Reference||',error='||errormsg||',time='||time||',abortcode='||abortcode||')' );
      rc = iter.next();
    end;
  run;

Super User
Posts: 11,343

Re: SAS Code issues

You likely want to use one of the quoting functions like %superq(error). Note: SuperQ does not want &error.

Regular Contributor
Posts: 152

Re: SAS Code issues

Hi Ballardw,

where should I put %superq(error)?

Super User
Super User
Posts: 7,050

Re: SAS Code issues

Why not use the data step to send the email instead of calling a macro?  That would eliminate the need to worry about macro quoting.

http://support.sas.com/documentation/cdl/en/hosto390/61886/HTML/default/viewer.htm#a001412669.htm

Regular Contributor
Posts: 152

Re: SAS Code issues

Hi Tom,

There are thousands record in SAS table each contains different email address.

I want to use hash iterator to read each email record in the table and execute the email macro  to send out the email to their corresponding users.

Thanks

Super User
Super User
Posts: 7,050

Re: SAS Code issues

Did you read the page I linked to?

You can use conditional logic in the DATA step to send multiple messages and to control which recipients receive which message. For example, suppose you want to send customized reports to members of two different departments. Here is a DATA step example:
Ask a Question
Discussion stats
  • 5 replies
  • 282 views
  • 0 likes
  • 3 in conversation