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

Morning all!

I tweaked some code I found online to mimic a graph. As a result, I am having issues troubleshooting....

Here is the code:

data table3;
  input Category $1-29 Variable $30-98 PrevRatio LowerCL UpperCL Pvalue;

  /*--Set up columns to create the stat tables--*/
  PR='PR'; LCL='LCL'; UCL='UCL'; p='p-value';

Pet Tick Encounter           Pet Tick Encounter in Past 6 Months								  2.81	2.29 3.45 0.001
Human-Pet Direct Interaction Walking dog on pavement/sidewalk only versus potential tick habitat  0.51	0.30 0.84 0.003
Human-Pet Direct Interaction Dog attends outdoor recreation activities							  1.51	1.22 1.88 0.001
Pet Behaviors 				 Dog ever hunts small animals										  1.66	1.30 2.13 0.001
Pet Behaviors 				 Cat ever hunts small animals										  1.57	1.05 2.34 0.03
Pet Behaviors 				 Dog ever rolls in animal carcasses								      1.74	1.38 2.20 0.001
Yard Features 				 Woods/Brush														  1.82	1.45 2.30 0.001
Yard Features 				 Pasture Land														  1.90	1.38 2.61 0.001
Yard Features 				 Compost Pile														  1.62	1.29 2.04 0.001
Yard Features 				 Log Pile															  1.60	1.29 1.97 0.001
Yard Features 				 Children's Play Equipment											  1.44	1.14 1.82 0.004

/*--Assign macro variables based on number of observations for use as Y axis offsets--*/
data _null_;
  call symputx("pct", pct);
  call symputx("pct2", 2*pct);
  set table3 nobs=nobs;

/*--Create custom style--*/
proc template;
   define style styles.table3Color;
      parent = Styles.analysis;

      style GraphFonts  from GraphFonts /                                                                
         'GraphDataFont' = ("<sans-serif>, <MTsans-serif>",7pt, bold)                                 
         'GraphValueFont' = ("<sans-serif>, <MTsans-serif>",7pt, bold);
      style GraphData1 from GraphData1 /                                      
         contrastcolor = GraphColors('gcdata2')                               
         color = GraphColors('gdata2'); 
      style GraphData2 from GraphData2 /                                      
         contrastcolor = GraphColors('gcdata1')                               
         color = GraphColors('gdata1'); 

/*--Set Style, DPI, image parameters and titles--*/
ods listing sge=off image_dpi=100 style=Styles.table3Color;
ods graphics / reset width=10in height=5in  imagename="Table3_2_table3PlotColor_V92";

title "Univariate Association Between Characteristics/Behaviors and Human Tick Encounter";
title2 h=10pt 'Prevalence Ratio and 95% CI';

/*--Create the plot--*/
proc sgplot data=table3; 

  scatter y=Variable x=Prevratio / group=Category xerrorupper=UpperCL xerrorlower=LowerCL markerattrs=(symbol=squarefilled);
  keylegend / title=' ' ;

  /*--Display statistics columns on X2 axis--*/
  scatter y=Variable x=PR / markerchar=PrevRatio x2axis;
  scatter y=Variable x=LCL / markerchar=LowerCL x2axis;
  scatter y=Variable x=UCL / markerchar=UpperCL x2axis;
  scatter y=Variable x=p / markerchar=Pvalue x2axis;

  /*--Draw other details in the graph--*/
  refline 0.1 1 10  / axis=x;
  refline 0.1 10 / axis=x lineattrs=(pattern=shortdash) transparency=0.5;
  inset 'Lower Risk of Tick Encounter'  / position=topleft;
  inset 'Higher Risk of Tick Encounter'  / position=top;

  /*--Set X, X2 axis properties with fixed offsets--*/
  xaxis type=log offsetmin=0 offsetmax=0.35 min=0.1 max=10 minor display=(nolabel);
  x2axis offsetmin=0.7 display=(noticks nolabel);

  /*--Set Y axis properties using offsets computed earlier--*/
  yaxis display=(noticks nolabel) offsetmin=&pct2 offsetmax=&pct2;

And the image is attached to help visualize but basically I want to reorder the variables in the graph to match how they are ordered in the datalines. (i.e. they should appear on the graph in reverse order from what they are now). I think ods is forcing a certain order but can't figure it....


Accepted Solutions
Meteorite | Level 14

Use REVERSE option on the yaxis statement.

View solution in original post

Meteorite | Level 14

Use REVERSE option on the yaxis statement.

Calcite | Level 5

Thanks for the quick response Sanjay_SAS. I knew it was something that simple....



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2 in conversation