I am running a sgpanel graph procedure like this:
proc sgpanel data=m_test_1;
panelby Storesl/columns=1 UNISCALE= column onepanel;
series y= avg x=N_date1 ;
colaxis integer interval =day TICKVALUEFORMAT=WEEKDAY3. ;
rowaxis integer ;
run;
The n_date1 variable is a date-time that has values of the for each weekday at each hour. The graph will only plot the date (see below) but I would like the weekday (Sun, Mon, etc.) only to be displayed. I've played with the tickvalueformat but it doesn't help, nor has a simple format statement. Same problems with a regular sgplot. Any ideas?
This works:
data timedata;
set sashelp.timedata;
/* Fake stocks */
do stock = "A", "B"; output; end;
run;
ods graphics / width=600 height=600;
proc sgpanel data=timedata;
where datepart(datetime) between "01jan2000"d and "14jan2000"d;
panelby stock / columns=1 onepanel;
series x=datetime y=volume;
colaxis type=time interval=day tickvalueformat=dtwkdatx3.;
run;
WEEKDAY format takes a DATE value for display. You say that "n_date1 variable is a date-time". So you are using an incorrect format.
Likely the approach to get what you might want is to build a custom format using proc format .
proc format library=work; picture dtwkdayname low - high ='%F' (datatype=datetime) ; run; data example; x='01JAN2019:12:20:00'dt; put x dtwkdayname3.; run;
Use the length 3 to show a 3-letter day of the week.
The picture format works as it should for proc print, but not in the sgplot procedures. Results are:
getting the literal '%f'. Am I doing something wrong?
@BigD wrote:
The picture format works as it should for proc print, but not in the sgplot procedures. Results are:
getting the literal '%f'. Am I doing something wrong?
Show your Proc Format and Sgplot code.
proc format library=work;
picture dtwkdayname
low - high ='%f' (datatype=datetime)
;
run;
ods graphics /reset height = 18in width = 11in;
ods html;
proc sgpanel data=m_test_1;
panelby store /columns=1 UNISCALE= column onepanel;
series y= avg x=N_date1 ;
colaxis integer TICKVALUEFORMAT=dtwkdayname3. ;
/*rowaxis integer ;*/
run;
ods html close;
I've also run it without the colaxis and use a format n_date_1 dtwkdayname3. with the same results: '%f' as the label
The problem with the custom format is that the SG procedures currently do no support the custom user date, time or datetime formats.
So that approach won't work.
This is one way to make date value with time bits turned into fractions of a day and may work.
Note that a wide range of dates may be misleading.
data junk; dt = '02JAN2019:12:30:00'dt; do i= 1 to 10; time= timepart(intnx('dtday',dt,i,'S'))/(24*60*60); plotdate= datepart(intnx('dtday',dt,i,'S')) + time; output; end; run; proc sgplot data=junk; series y= i x=plotdate; xaxis valuesformat=downame3.; run;
The Format for the X variable won't work but the values format on the xaxis works for this example. Without your data no promises.
This works:
data timedata;
set sashelp.timedata;
/* Fake stocks */
do stock = "A", "B"; output; end;
run;
ods graphics / width=600 height=600;
proc sgpanel data=timedata;
where datepart(datetime) between "01jan2000"d and "14jan2000"d;
panelby stock / columns=1 onepanel;
series x=datetime y=volume;
colaxis type=time interval=day tickvalueformat=dtwkdatx3.;
run;
A very subtle difference: I had colaxis type = integer instead of colaxis type = time. Works fine now.
I had originally tried the integer option a while ago to "force" non -decimal dates.
Thanks so much.
Bruce
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!
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.
Ready to level-up your skills? Choose your own adventure.