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

Dear All,

I have 1 more question regarding the following program. I have SAS 9.2 and 9.4.

The error bar is overlapped each other at the same date and obscures group differences. How to move one of the curves either left or right so that the error bars at the same date would not overlap?

Thanks!

data char;
input Date Rate1 RL Rate2 RU;

datalines;

0 . . . .
2 2.5 3.65 2.552 1.482
4 2.444 3.811 2.28 1.118
8 2.60 4.185 2.545 1.039
12 2.385 3.492 2.737 1.316
16 2.454 3.957 2.395 1.182
24 2.524 3.857 2.755 1.515
;

proc sgplot data=char;

xaxis  label='Date'  values=(0 to 24 by 4) ;

yaxis  label="Rate" values=(0.1 1 10 100) min=0.1 max=100 type=log logbase=10 logstyle=logexpand minor ;


series  x=Date y=Rate2 / lineattrs=(pattern=solid color=black thickness=1.5)
                             markers markerattrs =(size=9 color=black symbol=circle)
                             legendlabel='Rate2' name='Sbar';                      
scatter x=Date y=Rate2 / yerrorupper=RU  markerattrs =(size=9 color=black symbol=circle) ;

series  x=Date y=Rate1  / lineattrs=(pattern=dash color=black thickness=1.5) 
                             markers markerattrs =(size=9 color=black symbol=x)
                             legendlabel='Rate1' name='Ebar';                                           
scatter x=Date y=Rate1  / yerrorlower=RL  markerattrs =(size=9 color=black symbol=x) ;     

keylegend "Sbar" "Ebar"/position=topright location=inside across=1;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

With SAS 9.4, the easiest way would be to change your data to group structure, and use one series and one scatter with groups, with GroupDisplay=Cluster.  You can adjust the Cluster width. Not sure if this is right, but you get the idea.

data charGrp;

  keep date group value low high;

  set char;

  group='Rate1'; value=rate1; low=.; high=ru; output;

  group='Rate2'; value=rate2; low=rl; high=.; output;

  run;

proc sgplot data=charGrp;

xaxis  label='Date'  values=(0 to 24 by 4) ;

yaxis  label="Rate" values=(0.1 1 10 100) min=0.1 max=100 type=log logbase=10 logstyle=logexpand minor ;

series  x=Date y=value / group=group  legendlabel='Rate2' name='Sbar';                      

scatter x=Date y=value / group=group yerrorupper=high yerrorlower=low

        markerattrs =(size=9) groupdisplay=cluster clusterwidth=0.3;

keylegend "Sbar" / position=topright location=inside across=1;

run;

View solution in original post

2 REPLIES 2
Jay54
Meteorite | Level 14

With SAS 9.4, the easiest way would be to change your data to group structure, and use one series and one scatter with groups, with GroupDisplay=Cluster.  You can adjust the Cluster width. Not sure if this is right, but you get the idea.

data charGrp;

  keep date group value low high;

  set char;

  group='Rate1'; value=rate1; low=.; high=ru; output;

  group='Rate2'; value=rate2; low=rl; high=.; output;

  run;

proc sgplot data=charGrp;

xaxis  label='Date'  values=(0 to 24 by 4) ;

yaxis  label="Rate" values=(0.1 1 10 100) min=0.1 max=100 type=log logbase=10 logstyle=logexpand minor ;

series  x=Date y=value / group=group  legendlabel='Rate2' name='Sbar';                      

scatter x=Date y=value / group=group yerrorupper=high yerrorlower=low

        markerattrs =(size=9) groupdisplay=cluster clusterwidth=0.3;

keylegend "Sbar" / position=topright location=inside across=1;

run;

Johnlee
Calcite | Level 5

thanks Sanjay !!!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1180 views
  • 0 likes
  • 2 in conversation