BookmarkSubscribeRSS Feed
BillS
SAS Employee
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?
1 REPLY 1
Cynthia_sas
Diamond | Level 26
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:
[pre]
title "Today is: %sysfunc(today(),mmddyy10.)";
[/pre]

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.

cynthia
[pre]
proc sql;
select mean(age) format=5.2 into :avgage
from sashelp.class;
quit;

%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";
run;
[/pre]

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 861 views
  • 0 likes
  • 2 in conversation