Dear SAS community,
i've created a bar chart with SGPANEL with five panels. My panel headings consist of two variables (Pflanzenart and Mischung). I've put these two variables in one variable (Behandlung) for the panel headings and the categories for the panels. I want now that one part of the heading (Pflanzenart) is in one line and the other part (Mischung) is in a new line below: I've tried it with:
Behandlung = catx('0A'x, put(Pflanzenart, PflanzenartFmt.), put(Mischung, MischungFmt.));
but both, Pflanzenart and Mischung are standing together in one line followed by an empty line.
Here is the complete code:
/* Voreinstellungen */ ods html5 style=analysis path="D:\Masterthesis\Statistik\2024\Grafiken" file="Pflanzen-TM_25-4-24_NStufe.html"; ods graphics /reset; ods graphics / width=5in height=2.5in; ods escapechar='^'; title height = 1.5 "Median der Pflanzen-Trockenmasse der Düngerstufen"; footnote "Düngerstufen innerhalb einer Behandlung mit gleichem Buchstabe sind nicht signifikant voneinander verschieden."; /* Format für Duengerstufe*/ proc format; value NStufeFmt 0 = "0 kg N ha(*ESC*){unicode '207B'x}^{unicode '00B9'x}" 1 = "96 kg N ha(*ESC*){unicode '207B'x}^{unicode '00B9'x}"; run; /* Format für Pflanzenart */ proc format; value PflanzenartFmt 1 = "Erbse" 2 = "Gerste"; run; /* Format für Mischung */ proc format; value MischungFmt 0 = "RS" 1 = "90:10" 2 = "70:30" 3 = "80:40" 4 = "80:30" 5 = "50:50"; run; /* Datenvorbereitung */ data Pflanzen_TM_NStufe_MT1; set Pflanzen_TM_NStufe_MT1; Low = Median - Standardfehler; /* Untere Grenze Fehlerbalken*/ High = Median + Standardfehler; /* Obere Grenze Fehlerbalken */ LabelPos = High + 10.0; /* Position der Buchstaben */ Behandlung = catx('0A'x, put(Pflanzenart, PflanzenartFmt.), put(Mischung, MischungFmt.)); run; /* Erstellen des Balkendiagramms mit 2 Panels */ proc sgpanel data=Pflanzen_TM_NStufe_MT1; panelby Behandlung / noheaderborder headerattrs=(size=6pt weight=bold) novarname columns=8 rows=1; format Duengerstufe NStufefmt.; vbarparm category=Duengerstufe response=Median / group=Duengerstufe groupdisplay=cluster; highlow x=Duengerstufe low=Low high=High / group=Behandlung lineattrs=(color=black thickness=1 pattern=solid) /* Schwarze, durchgezogene Linie */ highcap=serif lowcap=serif; /* vertikale Striche an den Enden */ scatter x=Duengerstufe y=LabelPos / datalabel=Buchstabe /* Buchstaben für Fehlerbalken */ datalabelattrs=(size=10pt weight=bold color=black) datalabelpos=center /* Zentrierung der Buchstaben auf Fehlerbalken */ markerattrs=(size=0); /* Unsichtbarer Marker */ rowaxis label="Pflanzen-TM (kg ha^{unicode '207B'x}^{unicode '00B9'x})" labelattrs=(size=11pt); colaxis display=none; run; ods html5 close;
Could you help me to get the contents of the variable Pflanzenart in the first line of the panel heading and the contents of the variable Mischung in the second line of the panel headings?
Instead of combining the two variables into one, just keep them separate and specify both of them on the PANELBY statement. Since you have NOHEADERBORDER enabled, it should give you that appearance of "splitting" the two values. Hope this helps!
Instead of combining the two variables into one, just keep them separate and specify both of them on the PANELBY statement. Since you have NOHEADERBORDER enabled, it should give you that appearance of "splitting" the two values. Hope this helps!
Thank you really much, it worked 🙂
Here is DanH_sas 's way.
data have;
set sashelp.heart(obs=200);
run;
proc sgpanel data=have;
panelby status sex / novarname noheaderborder headerbackcolor=white;
scatter x=weight y=height;
run;
Alternative way is using INSET statement.
proc sgpanel data=have;
panelby status sex / noheader;
inset status sex/position=top nolabel textattrs=(size=10);
scatter x=weight y=height;
rowaxis offsetmax=0.15;
run;
Thank you for your explanation and the sample code. These were helpful 👍
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.