Desktop productivity for business analysts and programmers

Adding a sum to a Graph Title

SAS Employee
Posts: 5

Adding a sum to a Graph Title

I currently have a graph where I have broken expenditures down by month. What I am looking to do is add the current sum of all expenditures into the graph title.

I have been trying to use %sysfunc(sum(), so far unsuccessfully.

Should sysfunc work in this application? If not is there a way to do this?
Posts: 8,719

Re: Adding a sum to a Graph Title

Hi, Bill:
%SYSFUNC will allow you to use DATA step functions. However, it seems to me that %SYSFUNC is the wrong function to use in this context.
A very frequent use of %SYSFUNC is something more like this:
title "Today is: %sysfunc(today(),mmddyy10.)";

For what you want to do, you will have to get the summary number via another method (other than %SYSFUNC). The program below gets the average age of all the students in SASHELP.CLASS, by using PROC SQL and SELECT-INTO to create a macro variable which contains the average. Then, subsequent program steps can use that average in a TITLE statement (or in other statements). I just used a PROC PRINT instead of PROC GCHART, but you would be able to use the same technique with the Graph procedures. You just need to create a macro variable that holds your SUM -- before you use that macro variable in a TITLE statement.

proc sql;
select mean(age) format=5.2 into :avgage
from sashelp.class;

%let avgage = &avgage;
%put overall average age is: &avgage;

proc print data=sashelp.class;
title "Today is: %sysfunc(today(),mmddyy10.)";
title2 "The Average Age is &avgage";
Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation