BookmarkSubscribeRSS Feed
aggdmf
Calcite | Level 5

Hi all,

I have a sgplot in a macro that is looped to various filters in my dataset.  This all works great, except for when one of the filters has (almost) no data. Here's the macro:

 

 

%MACRO PLOT_WL(PHASE);
	ods graphics / noborder width=100%;
	proc sgplot data=input_workload_graph noborder;
		where upcase(fase)=upcase(&PHASEASE);
		vline date / response=amount_2wd lineattrs=(color=lightgrey thickness=3pt pattern=solid) legendlabel="2 workdays";
		vline date / response=amount_3wd lineattrs=(color=orange thickness=3pt pattern=solid) legendlabel="3+ workdays";
		xaxis display=(nolabel);
		yaxis display=(nolabel);
		keylegend / noborder;
	run;

I have two questions about the options for the axes:

 

  1. The first problem is that when there is no data to display the line for 0 is not at the x-axis but in the centre of the graph. How do I get it to align with the x-axis? I do not want to set 0 as a fixed minimum as for some filters this wouldn't apply. See below for how it looks now.

Output now (first question)Output now (first question)2.  If the filter results in smaller numbers, the y-axis displays decimal numbers. I'd like the y-axis to increment in whole numbers. I tried setting the valuesformat to this but this just displays the same 6 points on the y-axis pictured below but rounded to either 0 or 1. Ideally, the graph below only has two y-axis points. The 0 and 1. 

Output now (second question)Output now (second question)

Thanks in advance for the help!

 

1 REPLY 1
ballardw
Super User

One thing I might consider that could potentially solve both problems is instead of looping over values is to, possibly restructure the data, use SGPANEL with your Fase variable, suitably subsetted for all the graphs, as the panel by variable. Options in Sgpanel could make your graphs as one column and not in a single panel. The default behavior is uniform axis for both x and y variables. So unless your range of values has one vertical axis showing values of 0 to 1 and another that wants 0 to 10000 this may work better than the approaches that would involve

   1) check on your subset number of values for number of y values and set a different yaxis statement conditionally

   2) check on your subset range of values and determine appropriate yaxis values based on range

 

I really understand this issue because I have done similar in the past before we had Sgpanel and had to ineffect implement some of the Sgpanel behavior with macro coding and lots of it.

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1163 views
  • 0 likes
  • 2 in conversation