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

Hi, there:

 

 

I want to change "Squarefilled" marker to "Square with horizontal bar" in the code & the picture below.

data test;
    input x y lower upper @@;
    datalines;
    1 10 8 11 2 11 10 14 3 13 10 14
    4 13 11 15 5 14 12 16
    ;
run;
proc sgplot data=test;
    scatter x=x y=y / yerrorlower=lower yerrorupper=upper 
                      markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid);
    keylegend / noborder;
run;

 problem.JPG

I want to change this like the following picture.

wanted.JPG

 

To use LEGENDITEM Statement in SGPLOT seems to be an answer for my question, but this statement applies to SAS9.4M5 and to later releases. And my SAS is 9.4M3.

Please help me. Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
SuzanneDorinski
Lapis Lazuli | Level 10

This version uses annotation.  

 

data test;
	input x y lower upper @@;
	datalines;
    1 10 8 11 2 11 10 14 3 13 10 14
    4 13 11 15 5 14 12 16
    ;
run;

%sganno;

data anno;
  %sgline(x1=2.8,
          y1=6.43,
          x2=3.05,
          y2=6.43,
          drawspace='datavalue',
          linethickness=1);
run;

proc sgplot data=test sganno=anno;
	series x=x y=y / name="series" markers markerattrs=(symbol=squarefilled 
		color=blue) lineattrs=(color=blue pattern=solid thickness=0);
	scatter x=x y=y / name="scatter" yerrorlower=lower yerrorupper=upper 
		markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid);
	keylegend "series" / noborder;
run;

View solution in original post

11 REPLIES 11
Jay54
Meteorite | Level 14

Square filled marker with a line makes sense if you have a series plot with markers.  if you use SERIES plot with MARKERS, you should get a merged legend showing the marker with a line automatically.  I don't think you can get that if you only use the SCATTER statement.

KentaMURANAKA
Pyrite | Level 9

Hi, Mr. Sanjay:

 

 

Thank you for your response.

Like you said, I used SERIES statement with MARKERS option, and I got the result below.

data test;
    input x y lower upper @@;
    datalines;
    1 10 8 11 2 11 10 14 3 13 10 14
    4 13 11 15 5 14 12 16
    ;
run;
proc sgplot data=test;
    series x=x y=y / name="series" markers markerattrs=(symbol=squarefilled color=blue) lineattrs=(color=blue pattern=solid);
    scatter x=x y=y / name="scatter" yerrorlower=lower yerrorupper=upper 
                      markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid);
    keylegend "series" / noborder;
run;

output.JPG

I don't need lines that connect plots, but I can't find options to extinguish them.

Are there any option, etc. to delete them?

Thank you for your kind cooperation.

 

 

 

 

 

ballardw
Super User

@KentaMURANAKA wrote:

Hi, Mr. Sanjay:

 

 

Thank you for your response.

Like you said, I used SERIES statement with MARKERS option, and I got the result below.

data test;
    input x y lower upper @@;
    datalines;
    1 10 8 11 2 11 10 14 3 13 10 14
    4 13 11 15 5 14 12 16
    ;
run;
proc sgplot data=test;
    series x=x y=y / name="series" markers markerattrs=(symbol=squarefilled color=blue) lineattrs=(color=blue pattern=solid);
    scatter x=x y=y / name="scatter" yerrorlower=lower yerrorupper=upper 
                      markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid);
    keylegend "series" / noborder;
run;

output.JPG

I don't need lines that connect plots, but I can't find options to extinguish them.

Are there any option, etc. to delete them?

Thank you for your kind cooperation.

 


You requested a legend with a bar through the symbol. If there is no line through the symbol then having the legend appear that way implies something not displayed, i.e. the line through the symbol, is missing in the actual plot. I think that you need to  decide which is more important, the legend appearance or the legend actually matching the graph.

KentaMURANAKA
Pyrite | Level 9

Hi, ballarbw:

 

 

Thank you for your response.

Of course, I understand what you said, and I think whichever is good, "marker with bar" or "only marker".

But now I'm trying to re-analyze specific data, and previous result is expressed in the way I questioned.

Are there no options? I'm sorry, but please help me.

ballardw
Super User

The annotate facility will let you create a lot of stuff but that would be automatic. You have to provide location coordinates, for line segments start and end, color, line type, symbol and color as well as you having to provide coordinates that do not overlap other graph elements.

So create the legend for the SCATTER plot ant then create an annotate data set to add the line. There are a number of macros to help. Look at %SGLINE documentation to build a short line segment.

KentaMURANAKA
Pyrite | Level 9

Hi, ballardw:

 

 

Thank you for response.

Annotate Function......It feels like difficult for me now.

Mmm

Jay54
Meteorite | Level 14

You can get a combined marker and line in the legend if you use SERIES with the MARKER option.  You can set the line thickness=0.

KentaMURANAKA
Pyrite | Level 9

Hi, Mr. Sanjay:

 

 

Thank you for your response.

Like you said, I used THICKNESS=0 and got the following result.

But also in Legend, I want marker&line. Are there any options, which delete line only in graph, not legend?

I can't find, sorry.

 

Let me add more information.

I'm trying to re-analyze data (Who conducted the first analysis, I don't know).

They probably analyze using SAS, so I believe we can accomplish one I questioned.

data test;
    input x y lower upper @@;
    datalines;
    1 10 8 11 2 11 10 14 3 13 10 14
    4 13 11 15 5 14 12 16
    ;
run;
proc sgplot data=test;
    series x=x y=y / name="series" markers markerattrs=(symbol=squarefilled color=blue)
                     lineattrs=(color=blue pattern=solid thickness=0);
    scatter x=x y=y / name="scatter" yerrorlower=lower yerrorupper=upper 
                      markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid);
    keylegend "series" / noborder;
run;

 

 

SuzanneDorinski
Lapis Lazuli | Level 10

Add a legenditem statement, and then update the keylegend statement to only show the legenditem.

 

data test;
	input x y lower upper @@;
	datalines;
    1 10 8 11 2 11 10 14 3 13 10 14
    4 13 11 15 5 14 12 16
    ;
run;

proc sgplot data=test;
	series x=x y=y / name="series" markers markerattrs=(symbol=squarefilled 
		color=blue) lineattrs=(color=blue pattern=solid thickness=0);
	scatter x=x y=y / name="scatter" yerrorlower=lower yerrorupper=upper 
		markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid);
    legenditem type=markerline name="seriestype" /
      markerattrs=(symbol=squarefilled color=blue)
      lineattrs=(color=blue pattern=solid thickness=1)
      label='y';  
	keylegend "seriestype" / noborder;
run;

 

 EDITED TO ADD:  Legenditem statement is new in SAS 9.4M5, so won't work if you are using SAS 9.4M3.  Sorry!

SuzanneDorinski
Lapis Lazuli | Level 10

This version uses annotation.  

 

data test;
	input x y lower upper @@;
	datalines;
    1 10 8 11 2 11 10 14 3 13 10 14
    4 13 11 15 5 14 12 16
    ;
run;

%sganno;

data anno;
  %sgline(x1=2.8,
          y1=6.43,
          x2=3.05,
          y2=6.43,
          drawspace='datavalue',
          linethickness=1);
run;

proc sgplot data=test sganno=anno;
	series x=x y=y / name="series" markers markerattrs=(symbol=squarefilled 
		color=blue) lineattrs=(color=blue pattern=solid thickness=0);
	scatter x=x y=y / name="scatter" yerrorlower=lower yerrorupper=upper 
		markerattrs=(symbol=squarefilled) errorbarattrs=(color=blue pattern=solid);
	keylegend "series" / noborder;
run;
KentaMURANAKA
Pyrite | Level 9

Hi, Ms. Suzanne, All:

 

 

Thank you for your response.

Thanks to your code, I accomplished my objective.

 

 

Thanks a lot, All.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 11 replies
  • 1958 views
  • 6 likes
  • 4 in conversation