Creating an Animated Sequence

About Creating Animated Sequences Using the GIFANIM Device

To create an animated sequence with the GIFANIM device, you need to ensure that the resulting data stream is constructed properly. The GIFANIM data stream has three parts: header, body, and trailer.
To see an example of a program that uses the GIFANIM device, see Examples: Generating Animated GIF Images.

Preparing the Header

When creating a new animated GIF data stream, you must issue a GOPTIONS GSFMODE=REPLACE statement before you invoke the first SAS/GRAPH procedure. The device then constructs a new data stream by writing a valid GIF header and inserting graphical data from the first procedure.

Preparing the Body

After the first procedure has been executed, you must construct the body of the GIF animation. You can think of the body as all of the graphic images between the first and the last images in the sequence. Specify GSFMODE=APPEND in your GOPTIONS statement to suppress the header information and to begin appending graphic data to the current data stream. The GOPTIONS GSFMODE=APPEND statement must appear between the first and second SAS/GRAPH procedures.
Note: If you use BY-group processing on the first graphics procedure to generate multiple graphs, then the output is automatically appended to the same GIF file. Thus, you do not need to specify GSFMODE=APPEND for that first procedure. If you do not use a second graphics procedure to append additional graphs to the GIF file, you do not need to set the GSFMODE= graphics option in the body section of your program.

Preparing the Trailer

The final step in the GIF animation process is to mark the end of the animation by appending a GIF trailer (“3B”x) to the data stream. The way you do this depends on whether you use BY-group processing in the last procedure:
  • If you do not use BY-group processing in the last procedure, set GOPTIONS GEPILOG=“3B”X before the last SAS/GRAPH procedure.
  • If you use BY-group processing in the last procedure, do not assign a value to the GEPILOG= option. If you assign a value to GEPILOG=, because the GEPILOG= value is written after each graph in a BY-group, the GIF decoder interprets the first “3B”x as the end of the animation. Instead, use a DATA step to add the trailer to the data stream as follows:
    data _null_;
       file out recfm=n mod; 
       put "3B"x;
    run;
    In the preceding example, OUT is the file reference of the GIF output file.
After the animation is complete, issue a GOPTIONS RESET=ALL statement to prepare for subsequent SAS jobs.