Help using Base SAS procedures

Sending email using SAS

Reply
Frequent Contributor
Posts: 131

Sending email using SAS

Hi,

I just found a piece of code online, and tested it, and it worked. The code is below. My question is:

FILENAME myemail EMAIL TO="abc@gmail.com" FROM="BILL" IMPORTANCE="HIGH" SUBJECT="A test";

DATA _NULL_;

  FILE myemail;

  PUT "Please go to place A";

RUN;;

FILENAME myemail CLEAR;

If there are 5 places: A, B, C, D and E. I am interested to know how I can adapt the code so that:

1) the email will be sent every 1 hour;

2) each email will tell the random place to go (the above code tells to go to place A);

3) any place should not be visited twice.

Thanks a lot.

PROC Star
Posts: 7,363

Sending email using SAS

Some critical questions are:

1. How many people will this be going to?

2. Do you want to have approximately equal numbers assigned to each room each hour?

One possibility, assuming that it will be going to multiple people and you do want random assignment rather than simply random selection, would be to do all of the assignments up front, store them in the file, and then simply select the nth selection for each recipient each hour.

Frequent Contributor
Posts: 131

Sending email using SAS

Hi art297,

1. How many people will this be going to?

Suppose the exactly same email will be sent to 3 people.

2. Do you want to have approximately equal numbers assigned to each room each hour?

Each time, the same email will be sent to all 3 people. The contents are exactly the same.

PROC Star
Posts: 7,363

Re: Sending email using SAS

There are more direct methods, but I think the following may be easy to understand:

/*Create a file called rooms and, in it, assign the 5 rooms and a randomly generated number for each*/

data rooms;

  input room $;

  order=ranuni(0);

  cards;

A

B

C

D

E

;

/*sort the file by the randomly assigned number*/

proc sort data=rooms;

  by order;

run;

/*if your emails are going to go out every hour beginning at 1pm, assign the numbers*/

/*13 thru 17 to the randomly ordered rooms*/

data rooms;

  if _n_ eq 1 then hour=12;

  set rooms;

  hour+1;

run;

/*incorporate your email code in this datastep which selects each record*/

/*based on the hour of day and use windows are SAS scheduler to run the*/

/*program each hour*/

data select;

  set rooms (where=(hour=hour(timepart(datetime()))));

   *your email generating code;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 135 views
  • 3 likes
  • 2 in conversation