Hello,
I haven't used SGPLOT aside from the very basics. I have a Forest plot for which I would like to edit the labels. I would also like to reorder the variables so they match the order in the odds ratio table. In my example below, I would like to remove the variables names "Race_new" and "Sex" but keep "Age". I would also like to put "Age" in top followed by "Sex" and then "Race". I've been scouring SAS resources but I can't seem to find anything to address these questions specifically. My code can be found below. Any help would be greatly appreciated.
proc sgplot data=orci_a;
scatter x=oddsratioest y=effect / xerrorlower=lowercl
xerrorupper=uppercl
markerattrs=or
(symbol=DiamondFilled size=8);
refline 1 / axis=x;
xaxis label="OR and 95% CI " min=0;
yaxis label="Covariates";
run;
If you check your data I suspect that you find your Effect variable has values like "race_new Other vs White" as text.
Which means that you either take pass through a data step and modify the text for the effect variable as desired or create a format from the values you have to display "Other vs White" instead of "race_new Other vs White".
Since the current axis display order is using the alphabetical values you likely want to make the changes above and then see the result.
The YAXIS option Reverse would display the values alphabetically with the "top" of the Y axis as Age and and ascending alphabetical from there.
Or use an explicit values list such as:
proc sgplot data=sashelp.class; where name in ("Alfred" "Carol" "Janet" "Robert" ); scatter x=age y=name ; yaxis values= ("Janet" "Robert" "Carol" "Alfred"); /*the first value appears next to the Xaxis the last value furthest from x*/ run;
If you check your data I suspect that you find your Effect variable has values like "race_new Other vs White" as text.
Which means that you either take pass through a data step and modify the text for the effect variable as desired or create a format from the values you have to display "Other vs White" instead of "race_new Other vs White".
Since the current axis display order is using the alphabetical values you likely want to make the changes above and then see the result.
The YAXIS option Reverse would display the values alphabetically with the "top" of the Y axis as Age and and ascending alphabetical from there.
Or use an explicit values list such as:
proc sgplot data=sashelp.class; where name in ("Alfred" "Carol" "Janet" "Robert" ); scatter x=age y=name ; yaxis values= ("Janet" "Robert" "Carol" "Alfred"); /*the first value appears next to the Xaxis the last value furthest from x*/ run;
Brilliant! I can't believe I didn't think of that. Thank you.
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.