- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Dear SAS Community,
I would like to add a significance "*" symbol to the datalabel in sgpanel. I was able to add an "*" to the Season=2021 but I don't know how to also add it in the other seasons too, because the significance varies from season to season.
Here is my code and graphs:
This is how I would like to have the "*" symbols in all seasons:
data dlabel;
set one;
if Variety in('BL516') and Harvest in(1,2,6) and Season=2021 then dlabel="*";
else dlabel="";
run;
How could I also include
if Variety in('BL516') and Harvest in(8) and Season=2022 then dlabel="*" ?
title "DTR: BL516 vs Hass by Season and Harvest month";
proc sgpanel data=dlabel;
where Season in(2021, 2022, 2023) and Harvest in(1,2,3,4,5,6,8) and Variety in('BL516','Hass');
panelby Season/columns=3 onepanel ;
vline Harvest/response=DTR group=Variety stat=mean datalabel=dlabel ;
rowaxis values=(0 to 12 by 2) ;
run;
I would greatly appreciate your help!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That would be a lot of easy if you could post some real data to test your code.
Anyway, here could give you a start.
data have;
call streaminit(123);
do s=1 to 3;
do h=1 to 8;
do g=1 to 2;
v=rand('uniform');output;
end;
end;
end;
run;
proc sql;
create table have2 as
select *,max(v)+0.2 as max
from have
group by s,h
order by s,h
;
quit;
data have2;
set have2;
by s h;
call streaminit(123);
if first.h and mod(h,4)=rand('table',0.3,0.3) then label='*';
run;
proc sgpanel data=have2;
panelby s/onepanel rows=1;
series x=h y=v / group=g markers markerattrs=(symbol=circlefilled);
scatter x=h y=max/datalabel=label datalabelpos=top labelstrip datalabelattrs=(size=20 ) markerattrs=(size=0);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That would be a lot of easy if you could post some real data to test your code.
Anyway, here could give you a start.
data have;
call streaminit(123);
do s=1 to 3;
do h=1 to 8;
do g=1 to 2;
v=rand('uniform');output;
end;
end;
end;
run;
proc sql;
create table have2 as
select *,max(v)+0.2 as max
from have
group by s,h
order by s,h
;
quit;
data have2;
set have2;
by s h;
call streaminit(123);
if first.h and mod(h,4)=rand('table',0.3,0.3) then label='*';
run;
proc sgpanel data=have2;
panelby s/onepanel rows=1;
series x=h y=v / group=g markers markerattrs=(symbol=circlefilled);
scatter x=h y=max/datalabel=label datalabelpos=top labelstrip datalabelattrs=(size=20 ) markerattrs=(size=0);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much Ksharp! I will try to work out that code with my data.
If you don't mind, I have a another question:
I had to do some formatting in order to reorder the levels of the var 'Harvest' to (11,12,1,2,3,5) but the issue I am having is that even though the order in the graph is the order I want, the label is showing in the graph is 'tag' instead of 'Harvest'. How do I change the label?
I would very much appreciate it if you could let me know!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The best way to set the label in this case would be to use the LABEL statement inside of the SGPANEL specification:
label tag="Harvest";
This temporarily sets the column label within the scope of the procedure. That way, your axis label, tip labels, etc. pick up the label. It is also possible to set label="Harvest" on the ROWAXIS statement, but that will affect only the axis label.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It worked! Thank you so much!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Last question;
Is there a way to change the order of the line colors and the Variety legend so that GEM comes first in the legend and has the blue color instead? I have been trying different things but I still cannot figure it out.
Thank you so much!
title "DTR: GEM vs Hass by Season and Harvest month";
proc sgpanel data=one;
where Season in(2021, 2022, 2023) and Harvest in(1,3,4,5,6,8) and Variety in('GEM','Hass');
panelby Season/rows=1 onepanel ;
vline Harvest/response=DTR group=Variety markers markerattrs=(symbol=circlefilled) stat=mean ;
rowaxis values=(0 to 12 by 2) ;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Padding a blank before 'GEM' and PROC SORT it before PROC SGPANEL.
data have; call streaminit(123); do s=1 to 3; do h=1 to 8; do g='Hass' ,'GEM'; v=rand('uniform');output; end; end; end; run; data have; set have; if g='GEM' then g=' GEM'; run; proc sort data=have; by g; run; proc sgpanel data=have; panelby s/onepanel rows=1; vline h /response=v group=g markers markerattrs=(symbol=circlefilled) ; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much Ksharp. I tried the code and I am getting the order and colors I want, but I'm getting different data (below 2 DTR). I wonder what am I doing wrong.
data one;
call streaminit(123);
do Season=2021 to 2023;
do Harvest=1 to 8;
do Variety='Hass' ,'GEM';
DTR=rand('uniform');output;
end;
end;
end;
run;
data one;
set one;
if Variety='GEM' then Variety=' GEM';
run;
proc sort data=one;
by Variety;
run;
proc sgpanel data=one;
/*where Season in(2021, 2022, 2023) and Harvest in(1,3,4,5,6,8) and Variety in('GEM','Hass');*/
panelby Season/rows=1 onepanel ;
vline Harvest/response=DTR group=Variety markers markerattrs=(symbol=circlefilled) stat=mean ;
rowaxis values=(0 to 12 by 2) ;
run;
This is the data I should get:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
?? That is because you specify XAXIS value by "rowaxis values=(0 to 12 by 2) ;". You need to remove it if the real data don't fall in such range.
data one; call streaminit(123); do Season=2021 to 2023; do Harvest=1 to 8; do Variety='Hass' ,'GEM'; DTR=rand('uniform');output; end; end; end; run; data one; set one; if Variety='GEM' then Variety=' GEM'; run; proc sort data=one; by Variety; run; proc sgpanel data=one; /*where Season in(2021, 2022, 2023) and Harvest in(1,3,4,5,6,8) and Variety in('GEM','Hass');*/ panelby Season/rows=1 onepanel ; vline Harvest/response=DTR group=Variety markers markerattrs=(symbol=circlefilled) stat=mean ; /*rowaxis values=(0 to 12 by 2) ;*/ run;
If you want to put series in the middle of graph, you need to make sure the data value have such mean value.
data one; call streaminit(123); do Season=2021 to 2023; do Harvest=1 to 8; do Variety='Hass' ,'GEM'; DTR=rand('uniform')+6;output; end; end; end; run; data one; set one; if Variety='GEM' then Variety=' GEM'; run; proc sort data=one; by Variety; run; proc sgpanel data=one; /*where Season in(2021, 2022, 2023) and Harvest in(1,3,4,5,6,8) and Variety in('GEM','Hass');*/ panelby Season/rows=1 onepanel ; vline Harvest/response=DTR group=Variety markers markerattrs=(symbol=circlefilled) stat=mean ; rowaxis values=(0 to 12 by 2) ; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your reply Ksharp. If I remove it I get values from 0 to 1, that is why I set up the rowaxis values going from 0 to 12. What I want is my data to take these values:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That is reason I add 6 in my code.
DTR=rand('uniform')+6;output;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I added the 6 but I get this:
The original means go from 4 to 10 like in this excel graph. Is there a way to get the same original means in the same range as in this excel graphs?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
if your data has real value like this , you would get this graph .
Otherwise,you need to post your real data and see how is going.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
But in the first graph I made in sas, the data was the same as the one in the excel graph (on a range from 4 to 10). I attached my original data in excel. Probably I made not myself clear, but the only thing I wanted to change from this graph was to change the colors of the Varieties (not the data) so that the lines are red for Hass and blue for GEM (in case that is possible). So sorry for the confusion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I did not get any problem. You need the help of option "grouporder=ascending".
proc import datafile='C:\Users\xiakeshan\Documents\Downloads\dtr.xlsx' out=have dbms=xlsx replace;
run;
data one;
set have;
if strip(Variety)='GEM' then Variety=' GEM';
DTR=input(DTR__days_to_ripe_,best.);
run;
proc sgpanel data=one ;
where Season in(2021, 2022, 2023) and Harvest__month_ in(1,3,4,5,6,8) and strip(Variety) in ('GEM','Hass');
panelby Season/rows=1 onepanel ;
vline Harvest__month_/response=DTR group=Variety grouporder=ascending markers markerattrs=(symbol=circlefilled) stat=mean ;
rowaxis values=(0 to 12 by 2) ;
run;