BookmarkSubscribeRSS Feed
Kastchei
Pyrite | Level 9

 Howdy!  I have some odd behavior.  I don't need a solution, just looking for some explanation.  Here's my code.

 

proc sGPlot data = check pctLevel = group;
    vLine VisitDate / group = Consent stat = percent lineAttrs = (thickness = 2);
    refLine '14JAN2025'd '11MAR2025'd / axis = x lineAttrs = (thickness = 1);

    xAxis type = time interval = day values = ('01JAN2025'd to '31MAR2025'd by 1) noTimeSplit fitPolicy = rotate;
    format VisitDate e8601Da.;
run;

This code does not apply the format e8601Da. to the x-axis value text (Visit Dates).  Instead of showing 2025-01-01, it shows 01JAN25.  If I change the format to yymmdd10., the format is correctly applied.  It seems to be something particular with e8601Da. and similar date formats.  If I change the format to 10.2, it also does not correctly apply the format.  Instead of 23742.00, I only get 23742.  If I try e10.4, instead of getting 2.3742E4, I only get 2.374E4.  It appears that SGPLot is recognizing general classes of formats (regular number, scientific notation, date), but it is not honoring the specific format requested.

 

This is not specific to VLine.

data a;
    input x y;

    datalines;
1 1
2 2
3 3
4 4
;
run;

ods graphics / height = 2in width = 6in;
proc sGPlot data = a;  series x = x y = y;                       run;
proc sGPlot data = a;  series x = x y = y;  format x e8601Da. ;  run;
proc sGPlot data = a;  series x = x y = y;  format x yymmdd10.;  run;
proc sGPlot data = a;  series x = x y = y;  format x best.    ;  run;
proc sGPlot data = a;  series x = x y = y;  format x 1.       ;  run;

In this case, none of the formats are honored.

 

A second issue I figured out on my own.  SGPLot was not honoring either the values = () list nor the fitPolicy until I also added noTimeSplit.

 

A third issue is that I can only add a RefLine when the x-axis is designated a time axis: i.e., type = time.  When I format my dates as regular numbers (e.g. 23742), I can add a vertical reference line at any of those values without problem with any axis type.  But if I format them as a date without specifying that the x-axis is time, then the RefLines will not show up, no matter how I specify the values.  For example, none of these work.

    refLine  23742       / axis = x;
    refLine '01JAN2025'd / axis = x;
    refLine  01JAN2025'  / axis = x;
    xAxis;
    format VisitDate date9.;

The only way to get a reference line when the x-axis values look like dates is to specify like this.

    refLine '01JAN2025'd / axis = x;
    xAxis type = time;
    format VisitDate date9.;

 

I have solutions for my particular code: use type = time and use format yymmdd10..  I'm just trying to understand why these aren't working like I'd expect.  Is there a hidden rationale, or are these just limitations of SGPlot?

 

Happy holiday!

Michael

2 REPLIES 2
Quentin
Super User

One part of the answer (definitely not the whole answer) is that there is a documented list of formats that are not supported by the Graphics Template Language, and e8601da is on the list of unsupported formats.  https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatgraph/n0o4b33j6ue5bkn1viojbbvwzkba.htm

 

No clue what about the iso8601 formats would make them difficult to support in GTL.

 

I'd be curious to see the full code for an example of your third problem.  If adding the xaxis statement with type=time fixed the problem, then it's a good bet that without that, SGPLOT guessed that the axis type was linear.  You can end up with some weird looking plots if SGPLOT guesses the wrong axis type. In below example SGPLOT guesses the axis should be linear, because there is no format attached to the variable.  Using valuesformat will format the xaxis as dates, but note they repeat because it's a linear axis:

 

data a;
    input x y;
    datalines;
1 1
2 2
3 3
4 4
;
run;

proc sGPlot data = a; 
  scatter x = x y = y; 
  xaxis valuesformat=date9. ;
run;

Quentin_0-1766094729443.png

 

 

ballardw
Super User

If you want to display a dash in the date look at the YYMMDDXw format. The X position lets you use a list of characters in that position, B C D N P and S which will then use a Blank, Colon, Hyphen (dash), nothing, Period or Slash as the separator between the elements.

 

Note that custom rolled date, time and datetime formats created with Proc Format are also not going to display properly in graph axis.

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 2 replies
  • 130 views
  • 2 likes
  • 3 in conversation