I have a character variable on the y axis, and need to reverse the order.
I created a new numeric ordinal id variable in the excel version of the dataset, imported it to SAS, and reversed the order with proc sort.
It looked fine in proc print but in proc sgplot we did not have the desired order of the discrete variables.
Any ideas?
Also, if I want to use sgpanel, and have two variations of these figures side by side (1 row, 2 columns), how to I arrange for a y axis table to be on the right of each figure? Would also like to only label one of the y axes?
The default order for discrete values on a category axis (like this one) will be sorted in ascending alphabetic order. You can change that by setting the DISCRETEORDER option on the x-axis. Use DISCRETEORDER=DATA if you want to preserve the order of the values in the data set.
Thank you Sanjay:
Yes, I did try that after Iooked at :
DISCRETEORDER= DATA | FORMATTED | UNFORMATTEDspecifies the order in which discrete tick values are placed on the axis. Specify one of the following values:
DATA
With SGPLOT, HBAR (and HBOX, DOT) displays the values from top to bottom. This is different from other plots, where y axis is bottom to top. By default, the values are sorted. You can set DISCRETEORDER=DATA to get them in the same order as the data, top to bottom. REVERSE is not required. If you use REVERSE, the values will be bottom to top.
This is different from GTL, where the default direction for y-axis is bottom to top and DATA order by default.
data test;
input Name $ Value;
datalines;
B 10
A 5
D 12
C 9
;
run;
proc sgplot data=test;
hbar name / response=value nostatlabel;
yaxis discreteorder=data /*reverse*/;
run;
Thank you Sanjay.
Initially it seemed as though I would only be able to chart 95% CI's for the OR by using a scatter command , but it looks like HBOX is able to do this automatically. My OR and CI's are values that I have calculated from the study database and recorded in a secondary database, so OR is not a continuous variable that I can plot with the choices that "seem" to be available for HBAR and DOT.
Scatter has "scatter x=OR y=Vp / xerrorupper=UCL xerrorlower=LCL", so plotting those is easy enough. I cant see how to do this in HBAR and DOT.
If I have groups pdf variables that are "clustered" in terms of clinical significance, is there a way to create a space between the groups, or to have them indented (but starting from a left margin), with a subheading in the row above and indented more to the left?
it would be easier to help if you provide your code and some sample (non confidential) data to illustrate what you want or are doing. All plot statements (Scatter, HBox, Dot) support GROUP= option. The group values can be clustered using GROUPDISPLAY=cluster. Category values can be discrete or interval.
Here is the latest code I used and the output. Have made some progress.
How do you change the order of the table columns so the p values for mild and severe end up adjacent to their respective. Ors (CI)?
Will send the database in the next message .
proc template;
define style mystyle;
parent=styles.sasweb;
class graphwalls /
frameborder=off;
class graphbackground /
color=white;
end;
run;
ods listing close;
ods html style=mystyle path='.' file='newgraph.html';
ods graphics / reset=all border=off width=800 height=900;
/* sd OR's */
proc sgplot data =HEERDT.VP_Table2b2 nowall noborder ;
Title "OR (95% CI) for covariates across Vasoplegia Severity" ;
styleattrs datacontrastcolors=(CX18577A CX30CC6E ) ;
scatter x=sdOR y=Name / xerrorupper=sdUCL xerrorlower=sdLCL noerrorcaps markerattrs=(symbol=circlefilled size =5 )
group=Severity groupdisplay=cluster clusterwidth=0.6;
yaxis DISCRETEORDER= DATA reverse ;
xaxis display =(noticks nolabel noline) VALUEATTRS=(Color=Black Family=Arial Size=8 Style=Normal Weight=Normal)type =log logbase =10;
yaxis display =(noticks nolabel noline) VALUEATTRS=(Color=Black Family=Arial Size=8 Style=Normal Weight=Normal)
valueshalign=left colorbands=odd colorbandsattrs=(transparency=0.7);
refline 1.0 / axis=x discretethickness=1 lineattrs=(color=cxd0e0f0);
yaxistable pdp2_char sdORCI /class =Severity classdisplay =stack position=right location=outside
VALUEATTRS=(Color=Black Family=Arial Size=8 Weight=Normal ) VALUEHALIGN=CENTER VALUEJUSTIFY= CENTER CLASSORDER=DATA
COLORGROUP=Severity;
xaxis display=(nolabel) values=(0.4 1.0 1.5 2.0 2.5 5 6);
run;
Here is the SAS database.
I've done most things, except:
1) Create a space between sets of clinical variables.
(eg preoperative conditions should be separated from bypass time, volume of blood products etc.)
2) Possibly changing the shading so sets of variables are all shaded o e colour.
3) Place a subtitle above and slightly indented to the left of each of these sets.
4) p values in table for severe should be next to their OR (CI), not alternately. I would probably remove the table lable colours.
Thanks,
Christos
The data set "VP_Table2b.sas7bdat" does not have the variable PDP2_Char.
Some of the domain specific terminology you are using is not familiar to me.
It seems you may want something like a Subgrouped Forest Plot.
OMG.
Sorry about that!
Thats pretty embarrassing, here is the right database.
Have looked at the full code at the link you forwarded, but still unsure how to make subgroups. Will have to percolate on this overnight.
How can you create a space between potential subgroups?
I assume you want to create gaps between certain groups of observations (rows) in the table. Please see the idea in this article. Same can be done for y-axis too.
In the "Subgrouped Forest Plot" each group is merely another observation with missing odds ratio and statistics. These also have a different text color. The subgroup values (in each group) are indented using the YAxisTable option for indentation. The presence of the group headers provides the appearance of gaps. The article explains all this.
Sanjay:
Sorry about the late response. I have been trying to make this work, but am not able to get rid of the spaces yet on the categorical axis .
Maybe its an error that Im doing in formatting ?
I never did see how you can change the order of the columns though. I wanted to have two columns of p values and two for OR (CI), but to have the "Mild:" response first, and then the p columns and OR(CI) for the "Severe Response).
OK, so here is what I tried too do.
Relevant code in red, attachments demonstrate the output, and what is going wrong....
proc format;
value $Namefmt
"Age" ="Age"
..........etc....
"A" ="."
"B" ="."
"C" ="."
;
run;
proc template;
define style mystyle;
parent=styles.sasweb;
class graphwalls /
frameborder=off;
class graphbackground /
color=white;
end;
run;
ods listing close;
ods html style=mystyle path='.' file='newgraph.html';
ods graphics / reset=all border=off width=800 height=900;
proc sgplot data = HEERDT.Vasoplegia_space nowall noborder ;
Title "OR (95% CI) for covariates across Vasoplegia Severity" ;
styleattrs datacontrastcolors=(CX18577A CX30CC6E ) ;
scatter x=sdOR y=Name / xerrorupper=sdUCL xerrorlower=sdLCL noerrorcaps markerattrs=(symbol=circlefilled size =5 )
group=Severity groupdisplay=cluster clusterwidth=0.6;
yaxis DISCRETEORDER= DATA reverse valueformat= $Namefmt.;
xaxis display =(noticks nolabel noline) VALUEATTRS=(Color=Black Family=Arial Size=8 Style=Normal Weight=Normal)type =log logbase =10;
yaxis display =(noticks nolabel noline) VALUEATTRS=(Color=Black Family=Arial Size=8 Style=Normal Weight=Normal)
valueshalign=left colorbands=odd colorbandsattrs=(transparency=0.7);
refline 1.0 / axis=x discretethickness=1 lineattrs=(color=cxd0e0f0);
yaxistable pdp2_char sdORCI /class =Severity classdisplay =stack position=right location=outside
VALUEATTRS=(Color=Black Family=Arial Size=8 Weight=Normal ) VALUEHALIGN=CENTER VALUEJUSTIFY= CENTER CLASSORDER=DATA
COLORGROUP=Severity;
xaxis display=(nolabel) values=(0.4 1.0 1.5 2.0 2.5 5 6);
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: