Reuse a Graph with Different Data

5

This post is from SAS Author Sanjay Matange. It's part of our SAS Author Tips series.

Do you have a complex multi-cell graph created in ODS Graphics Designer that you’d like to reuse with different data? Ideally, you’d like to change the data without having to change the plots in each cell. The designer’s shared variable feature provides an easy way to build and reuse graphs with different data. With shared variables, you associate one or more shared variables with the data roles in your plots.

To create a shared-variable graph, select File > New > Blank Shared Variable Graph. Then define one or more shared variables.

Then, you build the graph by using the defined shared variables.  Now, changing the data assignment in a graph is simply a matter of changing the data assigned to the shared variables. You make this change once, and the change is applied to all the plots in the graph. Shared variables are most effective for creating graphs that have many plots and that use very few (one or two) variables.

You can also run shared-variable graphs in batch mode by using the SGDESIGN procedure. You can specify different variables in the same or in a different data set by using the DYNAMIC option.

Finally, you can use the DYNAMIC option to generate a dynamic title that changes to match the data that is used to generate the graph.

Now for some more fun…have a tip to share?

If you are among the first 5 people to comment on this blog post with a tip or trick related to this topic, you could win a hardcopy of either Clinical Graphs Using SAS® or SAS® ODS Graphics Designer by Example.

 

Be sure to enter your e-mail address when you write your comment so we can contact you if you are a winner. Only one book per commenter and for U.S. addresses only.

Want tips on other topics? Check out these great tricks.

Share

About Author

Cindy Puryear

Senior Marketing Specialist, SAS Publications

5 Comments

  1. John Dickens on

    At present my SAS Programming Experience within Credit Risk Analytics and Predictive Model Development as a Consultant suggests the use of Macro Variables and SAS Macros
    as the most common way to create a SAS Toolkit which can be used repeatedly on different but similar projects and which facilitates staff / Client training and development.

    I am not aware of any SAS Modules or Applications that support and enable the creation of Object-Oriented Code which facilitates Code re-use through inheritance.

    BTW Not everybody has access to SAS-IML.

    Would the creation of Stored Procedures or the use of PROC DS2 be a way forward?

    I would be very happy to get useful information about such tools.

    Regards

    • Cindy Puryear
      Cindy Puryear on

      John,

      Thank you for your comment and question. To answer this "Making an Object Reusable is always a great idea..." plus your second comment, making graphs reusable for dynamically changing data is not the same as "Object oriented". GTL graphs are designed to be reusable for changing data, even changing variable names. But inheritance and sub classing is different. That means you can actually use one graph and "extend" its features to do something else. That is not supported in ODS Graphics.

      SAS does have a new "Object Oriented" programming language called DS2 and you can find out more about this in our SAS Documentation. We have some books on this subject as well: https://www.sas.com/store/prodBK_68181_en.html?storeCode=SAS_US; https://www.sas.com/store/prodBK_68945_en.html.

      I will reply to you directly regarding the book offer.

      Thank you so much.
      Cindy

  2. John Dickens on

    Making an Object Reusable is always a great idea especially if the object supports inheritance.

    Imagine if SAS was truly Object Oriented at the User Interface Level; how much time and effort
    would we save by creating truly Resusable objects such as Graphs which depend dynamically on changing data

  3. Great post! Short, sweet, and useful.

    My tip is to always focus on the future when writing SAS code by making your code robust and re-usable. Sure, you may think the code or report is a one-off, but you never know when you may need it again. Use macro variables to help make code re-usable:

    %let dataset = work.employee_data;
    %let variable = salary;

    title "&dataset.";
    proc gchart data=&dataset.;
    vbar &variable.;
    run;

    There are some great papers for further reading, including this one.

    • Cindy Puryear
      Cindy Puryear on

      Thank you for your tip Mr. Kaefer, very helpful I am sure. I will reach out to you via email for mailing information along with your book choice.

      Cindy

Back to Top