Example: Create a Shared-Variable Graph and Add a Dynamic Title

About This Example

In this example, you create a graph that is similar to the previous example. The graph has two cells with different types of plots. The main distinction is that this example uses a shared variable. Shared variables make it easy to change the data that is used in the graph.
You also do the following:
  • specify that the plots share a common axis
  • change the height of the cells
  • add a generic title, and change the graph’s style
  • modify the graph to use a different variable and data set
  • modify the title to include dynamic content
  • generate the graph by using the SGDESIGN procedure
Here is the graph that you create in this example:
Shared-Variable Graph
Shared-Variable Graph
There are several ways to create and customize this graph. The following steps show one way to create the graph.

Step One: Create a Shared-Variable Graph and Assign Data

To create a shared-variable graph:
  1. Select Filethen selectNewthen selectBlank Shared Variable Graph. The Assign Data dialog box appears. A Shared Variables tab is active in the dialog box. The other tabs are present but are dimmed.
  2. In the Assign Data dialog box, complete these steps:
    • Select SASHELP from the Library list box.
    • Select CARS from the Data Set list box.
    • For the V1 shared variable, complete these steps:
      • Select HORSEPOWER from the Variable list box.
      • Select Numeric from the Type list box.
  3. Click OK.
  4. From the Plot Layers panel, click and drag the Histogram icon to the graph cell. The Assign Data dialog box appears and displays the Plot Variables tab.
  5. In the Variables section, select V1 (HORSEPOWER) from the X list box.
  6. Click OK.
  7. From the Plot Layers panel, click and drag the Normal icon to the graph. The Assign Data dialog box appears and displays the Plot Variables tab.
  8. In the Variables section, select V1 (HORSEPOWER) from the X list box.
  9. Click OK. The shared-variable graph has a histogram and a normal plot.

Step Two: Create the Second Cell and Add a Plot

  1. Right-click anywhere within the plot area and select Add a Row. A new row cell is added beneath the histogram.
  2. From the Plot Layers panel, click and drag the Box(H) icon to the new cell. The Assign Data dialog box appears and displays the Plot Variables tab.
  3. In the Variables section, select V1 (HORSEPOWER) from the Y list box.
  4. Click OK.

Step Three: Share a Common Column Axis

To share a common axis, right-click the Horsepower axis in either cell and select Common Column Axis.

Step Four: Change the Height of the Cells

You can increase the height of the cell that contains the histogram. This action decreases the height of the cell that contains the box plot.
To change the height of the cells:
  1. Position the cursor between the two rows. A dashed line appears between the rows and the cursor changes to a vertical two-headed arrow two-headed vertical arrow.
  2. Click and drag the dashed line downward. The box plot becomes shorter, and the histogram becomes taller.

Step Five: Add a Generic Title

In this step, you add a title to the graph. You need to keep the title generic because later you will change the data.
To add a title to the graph:
  1. Click Title icon in the toolbar. A new title text box is added above the graph.
  2. In the text box, enter Distribution Chart.

Step Six: Change the Graph’s Style

To change the graph's style:
  1. Right-click the graph and select Graph Properties. The Graph Properties dialog box appears.
  2. From the Style list box, select HtmlBlueCML.
  3. Click OK.

Step Seven: View the Result of the Initial Graph

Here is the result of the shared-variable graph that you have created.
Initial Shared-Variable Graph
Initial Shared-Variable Graph

Step Eight: Change the Graph Variable from Horsepower to Engine Size

Normally, if you want to change the variable that is used in a multi-cell graph, you would need to make the change in the individual plots. In a shared-variable graph, you can change the variable for all plots at one time.
  1. Right-click inside the plot area of a cell in the graph, and select Assign Data.
    The Assign Data dialog box appears.
  2. Click the Shared Variables tab.
  3. To reassign a data variable to the V1 shared variable, select ENGINESIZE from the Variable list box.
  4. Click OK.
Both cells of the graph change to reflect the new variable.
Shared-Variable Graph That Shows Engine Size
Shared-Variable Graph That Shows Engine Size

Step Nine: Change the Data Set

In the previous step, you reassigned a different variable to the shared variable. Suppose that you want to use the same graph with a different data set. This is easy to do when you use shared variables.
  1. Right-click inside the plot area of a cell in the graph, and select Assign Data.
    The Assign Data dialog box appears.
  2. Click the Shared Variables tab.
  3. Change the following:
    • Select CLASSFIT from the Data Set list box.
    • For the V1 shared variable, select WEIGHT from the Variable list box.
  4. Click OK.
The graph changes to reflect the new data set.
Shared-Variable Graph That Uses a Different Data Set
Shared-Variable Graph That Uses a Different Data Set

Step Ten: Add Dynamic Content to the Title

So far this example has used a generic title. Suppose that you want the title to more accurately reflect the data this is used for the graph. You can use dynamic content in the title.
  1. Double-click the title. The title enters edit mode.
  2. In the text box, enter Distribution of dyn(EXAMPLESV) .
Here is an example of the graph.
Shared-Variable Graph with Dynamic Content in the Title
Shared-Variable Graph with Dynamic Content in the Title
You must generate the graph by using the SGDESIGN procedure to replace the dynamic content in the title with actual text.

Step Eleven: Generate the Graph by Using the SGDESIGN Procedure

In this step, you use the SGDESIGN procedure to generate the graph.
In the SGDESIGN procedure, you use the DYNAMIC option to provide the text to substitute for the dyn(EXAMPLESV) expression.
To generate the graph:
  1. Save the graph so that you can reference it in the SGDESIGN procedure.
    1. Select Filethen selectSave As.
    2. Save the file to the desired location. Then complete these steps:
      • Enter the name svExample in the Filename text box.
      • Select SGD Files (*.sgd) from the File type list box. (This should be selected by default.)
    3. Click Save.
  2. In SAS, enter and submit the following program:
    proc sgdesign sgd="file-name-and-path" 
    	    dynamic EXAMPLESV="Class Weight";
    run;
    Replace file-name-and-path with the path to the graph. For example, the path might be "C:\SGDFiles\svExample.sgd".
    Note: In this example, you do not need to specify the value for the V1 shared variable. The example uses the default value WEIGHT.
For more information about the SGDESIGN procedure, see SGDESIGN Procedure in SAS ODS Graphics: Procedures Guide.
Here is the SAS output.
Shared-Variable Graph Output
Shared-Variable Graph Output