BookmarkSubscribeRSS Feed
_LB
Fluorite | Level 6 _LB
Fluorite | Level 6
Hello all;
I would like to know more about how to modify the ordering sequence in the X-axis output statement?

Currently I have the X-axis sequence as 2007Q1 2007Q2 etc etc. However I have been asked to use Jan-March 2007 vs 2007Q1. However, when I attempt to use vbar to graph it then alphabetizes so instead of getting:

Jan-March 2007 Apr-Jun2007 Jan-March2008 I get:
Jan-March 2007 Jan-March2008 Apr-Jun2007

Also on more question-Is there a way in within the X-axis to use ODS special characters such as /n so that I can relay additional informational such that:

Jan-March 2007
a=n
b=n
c=n

I know I am asking a tall order but any help would be greatly appreciated as I cannot find anything in SAS documentation.

Lawrence
6 REPLIES 6
Cynthia_sas
SAS Super FREQ
Hi:
With the SG procedures, you can specify an INSET statement, which is where I would tend to put the count information, instead of into the legend. It may be a moot point, because I believe that the ODS ESCAPECHAR functions like {unicode} will work in the legend, but not functions like the new line function.

Documentation for the KEYLEGEND statement is here:
http://support.sas.com/documentation/cdl/en/grstatproc/61948/HTML/default/discrete-stmt.htm

Documentation for the INSET statement is here:
http://support.sas.com/documentation/cdl/en/grstatproc/61948/HTML/default/inset-stmt.htm

An example of naming a plot and then generating a legend for that plot is shown here:
http://support.sas.com/documentation/cdl/en/grstatproc/61948/HTML/default/a003155743.htm

Note the legendlabel= option and the name= option and how they work together with the keylegend specification.

When I order date variables, even if I have a character variable, as you do for grouping, I generally sort by the date order before the graph step and then use ORDER=DATA or some option like that. For SGPLOT, the option is DISCRETEORDER=DATA. Rather than use a format, I generally make a character variable, that way, I don't have to remember to keep the format around everywhere.

cynthia

[pre]
proc format;
value mfmt
"01Jan08"d, "01Feb08"d, "01Mar08"d = "Jan-Mar 08"
"01Apr08"d, "01May08"d, "01Jun08"d = "Apr-Jun 08"
"01Jul08"d, "01Aug08"d, "01Sep08"d = "Jul-Sep 08"
"01Oct08"d, "01Nov08"d, "01Dec08"d = "Oct-Dec 08"
"01Jan09"d, "01Feb09"d, "01Mar09"d = "Jan-Mar 09"
"01Apr09"d, "01May09"d, "01Jun09"d = "Apr-Jun 09";
run;

data Clinic_Stats;
length month $5 Clinic $11;
infile datalines;
input monyy : monyy5. num_surg tot_pts Clinic $;
mgrp = put(monyy,mfmt.);
format monyy monyy5.;
label mgrp = 'Month'
monyy = 'Month'
num_surg = 'Number Surgeries'
tot_pts = 'Total Patients'
Contact_Resp = 'Respiratory Therapy Avg Time'
Clinic = 'Clinic';
return;
datalines;
JAN08 50 838 Main
FEB08 44 903 Main
MAR08 61 809 Main
APR08 53 489 Main
MAY08 53 249 Main
JUN08 40 285 Main
JUL08 41 242 Main
AUG08 57 292 Main
SEP08 49 298 Main
OCT08 63 497 Main
NOV08 64 920 Main
DEC08 62 907 Main
JAN09 67 854 Main
FEB09 68 896 Main
MAR09 75 865 Main
APR09 74 876 Main
;
RUN;

proc sort data=clinic_stats out=clinic_stats;
by monyy;
run;

ods listing;
proc sgplot data=clinic_stats;
vbar mgrp / datalabel stat=sum freq=num_surg;
title 'SGPLOT -- vbar ordered line and inset';
xaxis label = 'Month' fitpolicy=stagger type=discrete
discreteorder=data;
yaxis label = 'Total Surgeries' values=( 0 to 225 by 25);
inset (" Jan08 " = " 838" " Feb08 " = " 903" " Jan09 "=" 854") /
border
title='Patients' position=topright
textattrs=GraphLabelText;
run;

proc sgplot data=clinic_stats;
vbar mgrp / group=monyy datalabel stat=sum freq=num_surg;
title 'SGPLOT -- Grouped vbar ordered line and inset';
xaxis label = 'Month' fitpolicy=stagger type=discrete
discreteorder=data;
yaxis label = 'Total Surgeries' values=( 0 to 225 by 25);
inset (" Jan08 " = " 838" " Feb08 " = " 903" " Jan09 "=" 854") /
border
title='Patients' position=topright
textattrs=GraphLabelText;
run;

[/pre]
_LB
Fluorite | Level 6 _LB
Fluorite | Level 6
Cynthia;
Thanks for the post. Helps immensely. While we are on the subject-
it appears that the datalabel option does not appear to work with vbar although according to SAS there is that option.

What I would like to do is plot a rate for example but have the underlying frequency reported as well.
Ex: 20.0 Rate per 100 surgeries but only 1 SSI so it plots the rate but has n=1 printed on the top or side.
This can be accomplished with the series option but not the vline or vbar option.
I would be interested if this can be accomplished with vline or vbar.

Thank you again.
Lawrence
Cynthia_sas
SAS Super FREQ
Hi:
DATALABEL works for me with VBAR. I'm working with SAS 9.2 Phase 2. I believe there were some statements that were not fully implemented in 9.2 Phase 1 (or "classic" version).

For help with the SG procedures, your best bet is to work with Tech Support, as they can get to the "SG" developers if you have a question that they can't address.

cynthia
_LB
Fluorite | Level 6 _LB
Fluorite | Level 6
Cynthia;
Datalabels do work with Vline but not with Vbar. I will consult with tech support on this issue.
Thank you again for your help!
Lawrence
Cynthia_sas
SAS Super FREQ
Hi:
In 9.2 Phase 2, I can make my code and the DATALABEL option work. I did not try DATALABEL=variable. But the simple DATALABEL option -does- work with VBAR.

cynthia
DanH_sas
SAS Super FREQ
As for the axis ordering, your can specify data ordering for the axis. If you pre-sort your data, you can use the DISCRETEORDER=DATA option on the XAXIS statement to prevent the alphabetical sort of the axis.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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