14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8 Programming Methods 229<br />

Scheduling Actions<br />

to the log. For example, if you checked the schedule several times during the “hello” example, you would see<br />

something like this:<br />

Scheduled at 11.55000000000018 :Print("hello")<br />

Scheduled at 4.716666666666697 :Print("hello")<br />

Scheduled at 3.083333333333485 :Print("hello")<br />

The script might also be a name referring to a stored expression. For example, try submitting this script,<br />

which calls itself:<br />

quickieScript = expr( show("Hi there"); schedule(15, quickieScript); );<br />

quickieScript;<br />

This script should show the string “Hi there” in a log window after 15 seconds, and reschedule itself for<br />

another 15 seconds, continuing until the Stop button is clicked.<br />

More typically, in a production setting you might want to set up a schedule like this:<br />

FifteenMinuteCheck = expr(show("Checking data");<br />

open("my file", options...);<br />

distribution(column(column1), capability(spec limits));<br />

schedule(15*60, FifteenMinuteCheck));<br />

FifteenMinuteCheck;<br />

Schedule initiates an event queue, but once it has the event queued, JMP proceeds with the next statement<br />

in the script. For example, the following has results that might surprise you:<br />

schedule(3, print("one"));<br />

print("two");<br />

"two"<br />

"one"<br />

If you want the script to wait until the scheduled events are finished before proceeding, one solution would<br />

be to use Wait( ) with a suitable pause. Another is to embed the subsequent actions into the schedule<br />

queue. Schedule accepts a series of arguments to queue many events in sequence. Each event is a separate<br />

call to the schedule. Each event time is an absolute time relative to “now” (or the instant that Go is clicked).<br />

Therefore, the following sequence finishes in five seconds, not in twelve:<br />

schedule(3, print("hello"));<br />

schedule(4, print(", world"));<br />

schedule(5, print("--bye"));<br />

To cancel all events in a schedule queue, use Clear Schedule.<br />

scheduler[1]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!