BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
meederk
Calcite | Level 5

Hi All,

I am creating a timeline graph for a presentation for my internship involving the duration of participation for various customers of an app.  Variables that I have are the customer names (full_name), first week of participation (firstweekno), last week of participation (lastweekno), and duration of participation (dur_weeks).

data duration;
   input full_name firstweekno lastweekno dur_weeks Linetype;
   datalines;
SusieQueen 0 3 4
BillyJohnson 5 5 1
JonBonJovi 1 9 9
MaggieSimpson 2 8 7
EllisGrey 5 7 3
;
run;

 I'm using proc gplot and the annotate statement to create a timeline graph. The variables I'm currently using are full_name, firstweekno, and lastweekno.

data anno;
length function color $8;
retain xsys ysys '2' size 1 color 'red';
set duration;
function='move'; x=firstweekno; yc = full_name; output;
function='draw'; x=lastweekno; yc = full_name; output;
function='symbol'; text='dot';output;
run;

axis1 label=('Customer Duration of Participation') order= (0 to 32 by 1) minor=none;
axis2 label=('Customer Name');
symbol1 i=none;
title1 'Time Line';

proc gplot data=duration;
plot full_name*lastweekno / anno=anno;
label full_name= 'Customer Name';
label lastweekno= 'Duration of Participation by Week Number';
title 'Customer Duration of Participation';
run;
quit;

I like the graph that I get with this code, but I want to label each observation with the duration variable (dur_weeks).  Is this possible? If yes, can I use my existing code or am I going to need to start from scratch?

 

Thank you for any and all help!

Meeder

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

You can use the annotate function='label' to do that (in sas/graph gplot).

 

I've cleaned up your code a bit, and then basically added one extra line in your annotate code:

 

data duration;
length full_name $50;
input full_name firstweekno lastweekno dur_weeks;
datalines;
SusieQueen 0 3 4
BillyJohnson 5 5 1
JonBonJovi 1 9 9
MaggieSimpson 2 8 7
EllisGrey 5 7 3
;
run;

data anno; set duration;
length function color $8 text $20;
xsys='2'; ysys='2'; hsys='3'; when='a';
color='red';
function='move'; x=firstweekno; yc=full_name; output;
function='draw'; x=lastweekno; yc=full_name; size=.001; output;
function='symbol'; text='dot'; size=1; output;
function='label'; position='2'; size=1.8; color='gray33'; text=trim(left(dur_weeks)); output;
run;

axis1 label=('Customer Duration of Participation') 
 order= (0 to 32 by 1) minor=none offset=(2,2);
axis2 label=('Customer Name') value=(justify=right) offset=(3,3);
symbol1 i=none v=none color=gray h=8pt repeat=2;
title1 'Time Line';

title 'Customer Duration of Participation';
proc gplot data=duration;
plot full_name*firstweekno full_name*lastweekno / overlay 
 anno=anno haxis=axis1 vaxis=axis2;
run;

customers.png

 

 

View solution in original post

2 REPLIES 2
ballardw
Super User

@meederk wrote:

Hi All,

I am creating a timeline graph for a presentation for my internship involving the duration of participation for various customers of an app.  Variables that I have are the customer names (full_name), first week of participation (firstweekno), last week of participation (lastweekno), and duration of participation (dur_weeks).

data duration;
   input full_name firstweekno lastweekno dur_weeks Linetype;
   datalines;
SusieQueen 0 3 4
BillyJohnson 5 5 1
JonBonJovi 1 9 9
MaggieSimpson 2 8 7
EllisGrey 5 7 3
;
run;

 I'm using proc gplot and the annotate statement to create a timeline graph. The variables I'm currently using are full_name, firstweekno, and lastweekno.

data anno;
length function color $8;
retain xsys ysys '2' size 1 color 'red';
set duration;
function='move'; x=firstweekno; yc = full_name; output;
function='draw'; x=lastweekno; yc = full_name; output;
function='symbol'; text='dot';output;
run;

axis1 label=('Customer Duration of Participation') order= (0 to 32 by 1) minor=none;
axis2 label=('Customer Name');
symbol1 i=none;
title1 'Time Line';

proc gplot data=duration;
plot full_name*lastweekno / anno=anno;
label full_name= 'Customer Name';
label lastweekno= 'Duration of Participation by Week Number';
title 'Customer Duration of Participation';
run;
quit;

I like the graph that I get with this code, but I want to label each observation with the duration variable (dur_weeks).  Is this possible? If yes, can I use my existing code or am I going to need to start from scratch?

 

Thank you for any and all help!

Meeder


Basically with GPLOT you don't. You either have to build an Annotate data set or move to SGPLOT.

Your Annotate data set would have to have the additional text displayed.

 

Your data step does not run properly as it assumes the length of the names is 8 characters and there is no LINETYPE value. Since that isn't used anywhere I ignored it.

 

I strongly recommend moving graphic code to the newer SGPLOT, SGPANEL, SGSCATTER and SGRENDER as there are many more options, such as the one that you want for most types of plots, and the older procedures haven't had many improvements for many years.

 

data duration;
   input full_name :$15. firstweekno lastweekno dur_weeks ;
   datalines;
SusieQueen 0 3 4
BillyJohnson 5 5 1
JonBonJovi 1 9 9
MaggieSimpson 2 8 7
EllisGrey 5 7 3
;
run;

Proc sgplot data=duration;
   scatter x=lastweekno y=full_name/ datalabel=dur_weeks
                 markerattrs=(symbol=circlefilled color=red)
   ;
   xaxis label="Customer Duration of Participation" 
         values=(0 to 32 by 1)
   ;
   yaxis label='Customer name';
run;

The data step change reads the full name and drops line type.

 

Instead of AXISn statements the specific role is moved to and xaxis, yaxis (and/or xaxis2/yaxis2 to display axis in more places.

SCATTER places points at coordinates. Text axis can be odd for sort order though. The DATALABEL option is what you specifically requested. The MARKERTATTRS sets the marker type, note symbol has limited values, color should be pretty obvious. Other options in the Markerattrs set size.

Instead of SYMBOL or PATTERN statements you typically would use Group variable and the ODS Style in effect will select different colors, patterns and markers. Consider this:

Proc sgplot data=duration;
   scatter x=lastweekno y=full_name/ datalabel=dur_weeks
          group=firstweekno
   ;
   xaxis label="Customer Duration of Participation" 
         values=(0 to 32 by 1)
   ;
   yaxis label='Customer name';
run;

which changes the markers and the colors based on which is the firstweekno value. Maybe not of interest now but the GROUP=variable option coupled with a DATTRMAP data set lets you do things that GPLOT just won't without an extreme amount of programming, such as having the same color, symbol,linetype, text color and such stay the same for graphs where some of the values may not appear in all of them.

 

Also there are about 30+ types of graphs, including a TEXT graph which can eliminate many of the reasons Annotate data sets were used to provide text at different places in the graph.

 

 

 

GraphGuy
Meteorite | Level 14

You can use the annotate function='label' to do that (in sas/graph gplot).

 

I've cleaned up your code a bit, and then basically added one extra line in your annotate code:

 

data duration;
length full_name $50;
input full_name firstweekno lastweekno dur_weeks;
datalines;
SusieQueen 0 3 4
BillyJohnson 5 5 1
JonBonJovi 1 9 9
MaggieSimpson 2 8 7
EllisGrey 5 7 3
;
run;

data anno; set duration;
length function color $8 text $20;
xsys='2'; ysys='2'; hsys='3'; when='a';
color='red';
function='move'; x=firstweekno; yc=full_name; output;
function='draw'; x=lastweekno; yc=full_name; size=.001; output;
function='symbol'; text='dot'; size=1; output;
function='label'; position='2'; size=1.8; color='gray33'; text=trim(left(dur_weeks)); output;
run;

axis1 label=('Customer Duration of Participation') 
 order= (0 to 32 by 1) minor=none offset=(2,2);
axis2 label=('Customer Name') value=(justify=right) offset=(3,3);
symbol1 i=none v=none color=gray h=8pt repeat=2;
title1 'Time Line';

title 'Customer Duration of Participation';
proc gplot data=duration;
plot full_name*firstweekno full_name*lastweekno / overlay 
 anno=anno haxis=axis1 vaxis=axis2;
run;

customers.png

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 466 views
  • 3 likes
  • 3 in conversation