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';
datalines;
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
;
run;
/*--Assign macro variables based on number of observations for use as Y axis offsets--*/
data _null_;
pct=0.75/nobs;
call symputx("pct", pct);
call symputx("pct2", 2*pct);
set table3 nobs=nobs;
run;
/*--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');
end;
run;
/*--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;
run; 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....
... View more