BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
JeffMeyers
Barite | Level 11

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;
Adeoye
Obsidian | Level 7

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 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍

Adeoye_1-1622835902844.png

 

JeffMeyers
Barite | Level 11
Glad it worked for you. One last tip looking at the data. For the DISCRETELEGEND statement it's possible to put it into the bottom right blank space if you wanted to, but if you'd prefer them to be each of the graph cells you can add more spots to the ( ) after AUTOALIGN. For example you can set AUTOALIGN=(TOPRIGHT BOTTOMLEFT) and it'll pick which spot has the least collision with the graph automatically. If you want to add the legend to the bottom right space I believe you just cut the DISCRETELEGEND statement out of the current spot and paste it after the %do loop ends. Just change the name in the quotes to be treatment1 instead of treatment&i and it'll reference the legend in the top left cell. You might have to wrap it with a LAYOUT OVERLAY block, but I'm not positive.
Adeoye
Obsidian | Level 7

Hello Jeff,

You are on point. It sure looks better without legend on every single graph. Thank you.

Reeza
Super User
You should select Jeff's answer as the correct one, I think if you click the three dots at the side of my post you can unmark mine and mark his as correct 🙂
Adeoye
Obsidian | Level 7

Thank you Reeza. 👏

Chakraborty
Calcite | Level 5

@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?

Chakraborty
Calcite | Level 5

@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;

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 22 replies
  • 4227 views
  • 18 likes
  • 6 in conversation