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):
My initial Dataset looks like this.
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
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
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!
/* 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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.