BookmarkSubscribeRSS Feed
PGStats
Opal | Level 21

Hi, I have the following code

title "Hydro-Québec";
title2 "Production";
proc sgplot data=demande;
series x=date y=demandeGW / lineattrs=(thickness=2);
xaxis type=time display=(nolabel) offsetmin=0.05 offsetmax=0.05;
yaxis offsetmin=0.05 offsetmax=0.05;
refline 33 to 40 by 1 / axis=y noclip;
run;

Variable date has DATETIME. format. I like the resulting output:

PGStats_0-1642887205176.png

But I would like to get rid of the ":00:00" on the X axis, but to keep the date values on a separate line.

 

Any ideas?

PG
6 REPLIES 6
SASKiwi
PROC Star

What about a user-defined PICTURE format in PROC FORMAT? Selecting the DATETIME PICTURE option with the date and time components should get you what you want.

PGStats
Opal | Level 21

Thanks @SASKiwi . Good idea, but it seems like user-defined PICTURE formats are not expanded by proc SGPLOT on TIME axes. I also tried option INTERVAL=HOUR in the hope that it would reduce the displayed resolution of time values - it didn't.

 

proc format;
picture myTime (default=12)
low-high = '%d%b%y %H' (datatype=datetime);
run;

title "Hydro-Québec";
title2 "Production";
proc sgplot data=demande;
series x=date y=demandeGW / lineattrs=(thickness=2);
xaxis type=time display=(nolabel) offsetmin=0.05 offsetmax=0.05 valuesformat=myTime.;
yaxis offsetmin=0.05 offsetmax=0.05;
refline 33 to 40 by 1 / axis=y noclip;
run;

PGStats_0-1642910113335.png

 

PG
SASKiwi
PROC Star

What about GPLOT? Same problem? Have you checked your format with PROC PRINT or similar to confirm it has defined correctly?

Ksharp
Super User

Hi PGStats , Like this ?

 



data have;
do date='21jan2022'd to '22jan2022'd ;
 do time='00:00:00't to '24:00:00't by '01:00:00't;
  datetime=dhms(date,0,0,time);
  v=rand('normal');output;
 end;
end;
format datetime datetime.;
run;


proc sgplot data=have;
series x=datetime y=v / lineattrs=(thickness=2);
xaxis type=linear display=(nolabel) offsetmin=0.05 offsetmax=0.05 
values=('21jan2022:00:00:00'dt to '22jan2022:24:00:00'dt by '12:00:00't)
valuesdisplay=('21jan2022' '21jan2022:12:00:00' '22jan2022'  '22jan2022:12:00:00' '23jan2022')   ;
yaxis offsetmin=0.05 offsetmax=0.05;
run;

Ksharp_0-1642936392732.png

 

DanH_sas
SAS Super FREQ

What do you get if you set INTERVAL=HOUR on the XAXIS statement?

PGStats
Opal | Level 21

Thanks to everyone. What I ended up doing:

 

/* Create labels based on data */
proc sql noprint;
select 
    put (datepart(min(date)), nldate.),
    put (datepart(min(date)), yymmdd10.),
    intnx ("dtday", min(date), 0, "B") format=15.,
    put (datepart(min(date)) + 1, yymmdd10.),
    intnx ("dtday", min(date), 1, "B") format=15.
into 
    :titledate trimmed,
    :datelabel1 trimmed,
    :dateref1 trimmed,
    :datelabel2 trimmed,
    :dateref2 trimmed
from demande;
quit;

title "Hydro-Québec";
title2 "Production, depuis le &titledate.";
proc sgplot data=demande;
series x=date y=demandeGW / lineattrs=(thickness=2);
xaxis type=time display=(nolabel) offsetmin=0.05 offsetmax=0.05 valuesformat=tod2. ;
yaxis offsetmin=0.05 offsetmax=0.05;
refline &dateref1. &dateref2. / 
    axis=x lineattrs=(pattern=dot) labelloc=inside labelpos=min 
    label=("&datelabel1." "&datelabel2.") labelattrs=(size=8);
refline 20 to 40 by 1 / axis=y;
run;

PGStats_0-1643141747251.png

 

I won't mark my own answer as a solution, since it is close but not quite what I wanted, i.e. automatic tick labels on two lines outside the data frame without the ":00:00".

 

Btw the INTERVAL=HOUR option created full date:hour tick labels on a single line.

 

PGStats_1-1643142769053.png

 

PG

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!

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.

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
  • 6 replies
  • 1351 views
  • 5 likes
  • 4 in conversation