BookmarkSubscribeRSS Feed
JJ25
Calcite | Level 5

Hello everybody,

 

My first time asking a question in this forum,

 

I have a couple of figures made in Excel that I try to move to SAS EG for more automatic handling.

Unfortunately I got stuck on a couple of figures. What they has In common is that they use the same numeric variable across different groups.  

What I want is to use the same variable twice over different groups each with different attributes such as color and marker symbol.

This is what I want (From Excel):

 

JJ25_0-1666617985292.png

My initial Dataset looks like this.

JJ25_1-1666618005552.png

I want to plot the Avg and Rek variables over the Sek variable.

 

For this I try to use SGPanel, “panel by” Sek and two series Avg and Rek. I use an Attributemap where the Sek variable as the value

 

JJ25_2-1666618066988.png

I tried many different approaches. The closest I get is when I make a copy of the Sek variable (Sek2) since only one Attrid can be assigned to variable.

More over I created an additional grouping variable GroupAvg or GroupRek so I can group on this variable and use the Sek variables to control the attributes. This gives the names in the legend correct.

 

proc sgpanel data=omsattnig2 dattrmap=MyAttrMap;
	panelby sek / noborder nowall noheaderborder spacing=50 
 headerbackcolor=white headerattrs=(family=Arial size=16pt) novarname   
		headerbackcolor=white headerattrs=(family=Arial size=16pt) novarname;

series  X=year y=Avg / markers markerattrs=(size=15) lineattrs=(thickness= 4)
		group=GroupAvg grouplc=sek lcattrid=myregavg groupmc=sek mcattrid=myregavg groupms=sek msattrid=myregavg;

series  X=year y=Rek / markers markerattrs=(size=15) lineattrs=(thickness = 4)
		group=GroupRek grouplc=sek2 lcattrid=myregrek groupmc=sek2 mcattrid=myregrek groupms=sek2 msattrid=myregrek;
		
	rowaxis display=(nolabel noticks) valueattrs=(family=Arial size=12pt /*weight=bold*/) values=(0 to 14 by 2) 
		grid gridattrs=(thickness=2) offsetmin=0 offsetmax=0;
	colaxis display=(nolabel noticks) valueattrs=(family=Arial size=12pt /*weight=bold*/) 
		fitpolicy=rotate valuesrotate=vertical offsetmin=0;

	

		keylegend /  title='' noborder position=top  valueattrs=(size=12pt) autoitemsize across=4  ;
	format Avg Rek SPf.;
run;

 

The only remaining problem is that The legend only showing one of the attribute sets.

Probably because this is the same variable and this is the last one

JJ25_0-1666618188885.png

 

Maybe I misunderstood or overcomplicate things but I really starting to get out of ideas. Hope I made myself clear, a little hard to explain. Any help is appreciated.

I’m on version 7.15 of EG

 

Best regards!

2 REPLIES 2
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
You can use NOAUTOLEGEND in the PROC SGPANEL statement and then define separate legends with two KEYLEGEND statements in your code.Note you need to provide a label for each legend item that you define in the SERIES statement and then provide attributes for in the KEYLEGEND statement.

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n1txerz2g23a70n1kqo75gs8srla.htm
Ksharp
Super User
/* You could make two variables for avg and rek */
data have;
call streaminit(123);
do sek='K', 'R';
  do year=2011 to 2021;
    avg=rand('uniform');
 rek=0.1+rand('uniform');
 output;
  end;
end;
format avg rek percent8.2;
run;
data have2;
 set have;
 if sek='R' then do;avg2=avg;rek2=rek;call missing(avg,rek);end;
run;

proc sgpanel data=have2;
panelby sek /noborder nowall noheaderborder spacing=50  headerbackcolor=white  novarname  layout=panel ;
series  X=year y=Avg / markers markerattrs=(size=15 symbol=circlefilled color=brown) lineattrs=(thickness=4 color=brown)  legendlabel='Avg';
series  X=year y=rek / markers markerattrs=(size=15 symbol=circlefilled color=orange) lineattrs=(thickness=4 color=orange) legendlabel='Rek';
series  X=year y=Avg2 / markers markerattrs=(size=15 symbol=circlefilled color=navy) lineattrs=(thickness=4 color=navy) legendlabel='Avg';
series  X=year y=rek2 / markers markerattrs=(size=15 symbol=circlefilled color=blue) lineattrs=(thickness=4 color=blue)legendlabel='Rek' ;
keylegend  /position=top noborder;
run;

Ksharp_0-1666698735699.png

 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 427 views
  • 0 likes
  • 3 in conversation