Data visualization with SAS programming

Proc GPLOT cutting off data?

Reply
New Contributor
Posts: 4

Proc GPLOT cutting off data?

Hey guys, I was hoping you could help me out.

I am trying to plot some time series data but when I force a start/end/interval, the end data gets cut off at the final tick mark.

For example, I am graphing data from 1/1/02 to 2/4/10 and I want the axis to end at 2/4/10 when the data stops (everything plots fine with no order statement but the axis goes until 2011).

If I make an order statement, unless the by interval exactly ends with the last tick mark on 2/4/10, the chart will cut off everything after the final tickmark. In this example, I could have 5 tickmarks with an interval of 739 days and it would be fine (since the final tick mark is on 2/4/10) but if I tried to use "by year", it would place the last tick mark on 1/1/10 and not graph the remaining month or so of data.

Is there any way to get gplot to go beyond the final tick mark?
Thanks
SAS Employee
Posts: 963

Re: Proc GPLOT cutting off data?

I assume you are using 'proc gplot'?

What device are you using? such as device=png.

Could you show us the exact axis statement?
New Contributor
Posts: 4

Re: Proc GPLOT cutting off data?

using device=SASPRTC and ods pdf

an example axis would be:
axis1 order= '01jan02'd to '04feb10'd by year;

The data being has a date and a value for each trading day in the above date range.
Again, this plots fine without an order statement (but the axis doesn't cut off at 2/4/10 like I want it to).
I can make it work if I do:
axis1 order= '01jan02'd to '04feb10'd by 739;
since 739 is a factor of the number of days between the dates but this will only work when there are exact factors (the number of days between 1/1/03 and 2/4/10 is prime so there is no solution) and it gives me zero control over how many tick marks I would like.

Ideally, I would be able to have a tick mark on january 1st of every year (or several tick marks per year) and not have to worry about my data being cut off before the end.
SAS Employee
Posts: 963

Re: Proc GPLOT cutting off data?

I think that if you're using "by year" in an axis order statement, you will need to make sure that your 'from' and 'to' values are evenly space by year.

In a case like yours, I'm not sure that the software would know what to do ...

order= '01jan02'd to '04feb10'd by year

I think you'll need to use something like ...

order= '01jan2002'd to '01jan2011'd by year
New Contributor
Posts: 4

Re: Proc GPLOT cutting off data?

Even if I don't use by year (say I use 'by 200'), this error crops up.

If I do
order= '01jan2002'd to '01jan2011'd by year
It will pull my date axis all the way out to 1/1/2011 leaving a bunch of blank space which I do not want (this is what happens if I simply use no order statement at all).

an example of what I want would be if you graphed the following data in excel:
1/1/2010 5
1/2/2010 6
1/3/2010 7
1/4/2010 8
1/5/2010 9
1/6/2010 10
and set the axis min to 1/1/2010, axis max to 1/6/2010, and major unit to 3, it would print axis labels for 1/1/2010 and 1/4/2010 but it would still graph the values for 1/5/2010 and 1/6/2010 (SAS just cuts these off)
SAS Employee
Posts: 963

Re: Proc GPLOT cutting off data?

I guess it's a matter of preference, and I can see advantages and disadvantages to doing it either way.

Personally, I prefer the gplot way - only plot the markers that fall within the axes. Imho, if you plot markers that are outside the axis min/max values, then you could run into data-integrity problems of the end user assuming the markers fall within the axis min/max values, when they actually don't (this is especially problematic when the values are just barely outside the axis min/max).

That being said, I believe that is the way the new 'proc sgplot' handles axes, so you might want to give that a try, if you've got v9.2
New Contributor
Posts: 4

Re: Proc GPLOT cutting off data?

Well, I want the markers that fall within the axes...they just don't fall within the tick marks.

Thanks for the sgplot suggestions. I would prefer to use it but I have to get this to work on 9.1 so I guess I will just stick with finding a factor that fits my time period.
Valued Guide
Posts: 632

Re: Proc GPLOT cutting off data?

You could make a user defined format that covers all the days and then only shows the values for selected days. Consider the following GPLOT example.
[pre]
data a(keep=y date)
cntl(keep=fmtname start label hlo);
do date='01jan02'd to '08feb05'd;
y+1;
output a;
retain fmtname 'axdate';
start=date;
if month(date)=1 and day(date)=1 then label=put(date,date9.);
else label=' ';
output cntl;
end;
hlo='o'; label=' '; output cntl;
label=
run;
proc format cntlin = cntl;
run;
axis1 order='01jan02'd to '08feb05'd;
proc gplot data=a;
plot y*date/haxis=axis1;
format date axdate.;
run;
quit;
[/pre]
SAS Super FREQ
Posts: 864

Re: Proc GPLOT cutting off data?

For classic SAS/GRAPH procedures like GPLOT, the data is bounded by the first and last tick marks. The only way I can think of to get around that is to use annotate. However, if you're a using SAS 9.2, the ODS Graphics system does not have this limitation. You could use PROC SGPLOT to display the desired tick marks without affecting your data range. Let me know if you want more details.

Thanks!
Dan
Post a Question
Discussion Stats
  • 8 replies
  • 508 views
  • 0 likes
  • 4 in conversation