BookmarkSubscribeRSS Feed
bncoxuk
Obsidian | Level 7

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.

3 REPLIES 3
art297
Opal | Level 21

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.

bncoxuk
Obsidian | Level 7

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.

art297
Opal | Level 21

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1180 views
  • 3 likes
  • 2 in conversation