Ah yes, I forgot to put the VIEWMIN and VIEWMAX values in for the y-axis. I've added several macro variables for min/max values to use in the VIEWMIN/VIEWMAX options below. There are more streamlined ways to do this but I'm making it more verbose to read easier to what I'm doing. Look for the VIEWMIN and VIEWMAX options below as this sets what is visible in the axis.
As for the ylabel being spaced a bit. This is because it doesn't exist in the same space as the y-axis tick marks. The wider the tickmarks are the further the y-axis label will be. It won't look as bad when there are actual tick values showing up appropriately, but the only real way to make it closer is to use annotation which is another animal. I can explain how to do that if needed, but try the changes below to see if that helps at all.
Here is some updated code:
%Macro TestSee;
proc format;
value $treatmentFmt
"Bov" = "PRO-A"
"BovC" = "PRO-B"
"Control" = "CON"
;
run;
ODS PATH work.templat(update) sasuser.templat(read) sashelp.tmplmst(read);
PROC TEMPLATE;
DEFINE STATGRAPH _grid;
BEGINGRAPH / designheight=10in designwidth=8in;
%Let value1=start=650 end=750 increment=10; %let min1=650; %let max1=750;
%Let value2=start=1.0 end=2.0 increment=0.1; %let min2=1; %let max2=2;
%Let value3=start=1 end=2.0 increment=0.1; %let min3=1; %let max3=2;
%Let value4=start=2 end=5 increment=0.1; %let min4=2; %let max4=5;
%Let value5=start=35 end=45 increment=1; %let min5=35; %let max5=45;
%Let ylabel1=BW, kg; %Let ylabel2=ECM/DMI, kg/kg; %Let ylabel3=Milk Fat Yield, kg; %Let ylabel4=Milk Fat Percentage, %; %Let ylabel5=Milk Yield, kg;
%Let xlabel=Week of Trial;
DISCRETEATTRMAP name='styles' / ignorecase=true;
value 'PRO-A' / markerattrs=(symbol=circlefilled color=darkblue) lineattrs=(pattern=shortdash color=darkblue);
value 'PRO-B' / markerattrs=(symbol=trianglefilled color=darkred) lineattrs=(pattern=solid color=darkred);
value 'CON' / markerattrs=(symbol=squarefilled color=darkgreen) lineattrs=(pattern=mediumdash color=darkgreen);
ENDDISCRETEATTRMAP;
DISCRETEATTRVAR attrvar=_attrvar_ var=treatment attrmap='styles';
LAYOUT LATTICE / rows=3 columns=2;**Use ORDER=ROWMAJOR or COLUMNMAJOR to determine if the graphs fill top to bottom or left to right;
%do i = 1 %to &obs; CELL; CELLHEADER; ENTRY halign=left 'This is where a title goes'; ENDCELLHEADER;
LAYOUT OVERLAY / xaxisopts=(type=linear label="&xlabel." linearopts=(tickvaluesequence=(start=1 end=12 increment=1) viewmin=1 viewmax=12)
Labelattrs=(Family='Arial' Size=11 weight=Bold ) tickvalueattrs=(size=10))
yaxisopts=(label="&&ylabel&i" Labelattrs=(Family='Arial' Size=11 weight=Bold ) tickvalueattrs=(size=10)
type=linear linearopts=(tickvaluesequence=(&&value&i) viewmin=&&min&i viewmax=&&max&i));
Seriesplot x=eval(ifn(resp_name="&&resp&i",Period,.)) y=estimate/ group=_attrvar_ display=all lineattrs=(thickness=1) name="Treatment&i";
Scatterplot x=eval(ifn(resp_name="&&resp&i",Period,.)) y=estimate/ group=_attrvar_ name="a&i" YErrorUpper=Upper YErrorLower=Lower;
discretelegend "Treatment&i"/ title="Treatment:" location=inside autoalign=(topright) across=1;
ENDLAYOUT; ENDCELL;
%end;
ENDLAYOUT;
ENDGRAPH;
END;
RUN;
Proc SGRENDER data = Selected template=_grid;
format treatment $treatmentFmt.;
RUN;
%mend;
%TestSee;
Hi Jeff Meyers,
Don't you need a certificate to be this awesome?! 😁 The viewmin and viewmax totally fixed the problem. You just made my day sir 😍
THANK YOU! And again, a million LIKES for you 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍
Hello Jeff,
You are on point. It sure looks better without legend on every single graph. Thank you.
Thank you Reeza. 👏
@JeffMeyers This code was really helpful for me to create a similar layout. However, I have to display formats for x-axis in each cell. The values of x-axis are visit numbers and numeric in nature. Could you please help me on that?
@JeffMeyers The problem is little bit different now. I have used the format as eval(put(ifn(paramcd="MDS", avisitn,.),vs.)). I have now used type=linear for xaxisopts as the visit numbers are not equidistant. However, I got warning as:
WARNING: SCATTERPLOT statement has a conflict with the axis type. The plot will not be drawn.
WARNING: SERIESPLOT statement has a conflict with the axis type. The plot will not be drawn.
I think linear axis option is not compatible with put fuction due to conversion to character format. Is there any way to solve this?
The format "vs" is defined as:
proc format;
value vs
2="Pre-D0"
3="Post-D0"
6="Pre-W3"
7="Post-W3"
;
run;
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.