BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
samp945
Obsidian | Level 7

Hello all,

 

I am using by group processing to create a number of separate plots. SAS creates sequentially numbered file names with ODS listing and ODS graphics statements. I can also create dynamic titles according to the by group by following the tips from a great blog post.

 

However, I am required to title each plot with a sequential number (e.g., Figure 2.01: Example Title#1; Figure 2.02: Example Title#2, etc.). Is there some way to create sequentially numbered titles when using by group processing? I have tried searching for relevant keywords with no luck.

 

Thanks for reading!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
Why not create a GROUP variable in which there are 1,2,3 series number and using the skill you refered to ?

proc sort data=sashelp.class out=temp;
by age weight;
run;
data temp;
set temp;
by age;
n+first.age;
run;
option nobyline;
title "Title##byval1";
proc sgplot data=temp;
by n;
series x=weight y=height;
run;

View solution in original post

6 REPLIES 6
Ksharp
Super User
Why not create a GROUP variable in which there are 1,2,3 series number and using the skill you refered to ?

proc sort data=sashelp.class out=temp;
by age weight;
run;
data temp;
set temp;
by age;
n+first.age;
run;
option nobyline;
title "Title##byval1";
proc sgplot data=temp;
by n;
series x=weight y=height;
run;
samp945
Obsidian | Level 7

Very clever! I am able to use both #ByVal1 (the main by group category name) and #ByVal2 (the figure number) in the plot title.

 

I am already familiar with first.variable and last.variable, but can you point me toward documentation for the N+ strategy you used? I don't know what it is called or quite understand how it would be used in other applications.

Ksharp
Super User
Here
n+first.age;
is the identity with
if first.age then n+1;
samp945
Obsidian | Level 7

Thanks! What if I would like to begin the numbering at a specific number instead of 1? For example, if I want "n" to begin at 8?
run;

Ksharp
Super User
Give it an initial value 7 by RETAIN statement, as the URL posted by Tom.

data temp;
set temp;
by age;
retain n 7;
n+first.age;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 2266 views
  • 3 likes
  • 3 in conversation