BookmarkSubscribeRSS Feed
gyambqt
Obsidian | Level 7

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;

5 REPLIES 5
ballardw
Super User

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

gyambqt
Obsidian | Level 7

Hi Ballardw,

where should I put %superq(error)?

Tom
Super User Tom
Super User

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

gyambqt
Obsidian | Level 7

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

Tom
Super User Tom
Super User

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:

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 926 views
  • 0 likes
  • 3 in conversation