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

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. 

 

 

joesmama_0-1619037563001.png

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

3 REPLIES 3
Reeza
Super User
FYI - I moved your post to the graphics forum, which is more appropriate for your question. It would be helpful if you could provide some data to work with as well, or use one of the examples from the blog posts as a starting point so it's easier to someone to help out.

Can't really run your code without data, fake data is totally fine.
https://blogs.sas.com/content/?s=forest+plot
ballardw
Super User

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;
joesmama
Obsidian | Level 7

Brilliant! I can't believe I didn't think of that. Thank you.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 1469 views
  • 0 likes
  • 3 in conversation