Data visualization with SAS programming

Picture Formats Not Rendered in PROC SGPLOT

Reply
New Contributor
Posts: 4

Picture Formats Not Rendered in PROC SGPLOT

[ Edited ]

Should I be able to use a picture format in SGPLOT?

 

I created a picture format using a date directive for the week number ('%W').

 

When I generate a scatter plot using PROC SGPLOT, the x-axis tick labels are rendered as %W instead of 01, 02, 03, etc.

 

However, if I use my picture format with PROC GPLOT, the x-axis tick labels are displayed correctly.

 

(I'm familiar with the weekw3. format, but I don't want the extra 'W' in front of every value in my x-axis -- W01, W02, W03, etc.  And I need to use some specific features of SGPLOT rather than reverting to GPLOT.)

 

I found a few other posts on this topic, but the suggested workaround is to convert the x-axis variable to a formatted character value.  I don't think my irregularly-spaced time series data will be plotted correctly if I convert all the dates to formatted characted values.

 

Related Post #1

 

* Related Post #2

 

Does anyone have any insights about using picture formats in PROC SGPLOT?

 

Thanks in advance...

Frequent Contributor
Posts: 144

Re: Picture Formats Not Rendered in PROC SGPLOT

[ Edited ]

Hi, 

I don't know if it's a proper solution, but you always could extrat your TPL code from the SGPLOT (option TMPLOUT) and edit the layout XAXISOPTS with something like that if you know the number of weeks.

Layout overlay / XAXISOPTS= (LINEAROPTS=(tickvaluelist=(1 2 3) 
                         tickdisplaylist=('01' '02' '03')))

 

SAS Super FREQ
Posts: 1,141

Re: Picture Formats Not Rendered in PROC SGPLOT

Respected Advisor
Posts: 4,819

Re: Picture Formats Not Rendered in PROC SGPLOT

@Sanjay_SAS, Function-formats (fcmp) don't work with sg procs either. 

 



proc fcmp outlib=work.fcmp.fmt;
   function weekfmt(date) $2;
      return(put(week(date),z2.0));
   endsub;
run;

options cmplib=(work.fcmp);

proc format; 
   value weekfmt 
         other=[weekfmt()]; 
run;

/* Doesn't work */
proc sgplot data=sashelp.Citiday;
format date weekfmt.;
series x=date y=SNYDJCM;
run;

/* But this works */
proc print data=sashelp.citiday(obs=20); 
format date weekfmt.; 
run;
PG
Respected Advisor
Posts: 4,819

Re: Picture Formats Not Rendered in PROC SGPLOT

You could get away with something like this, I guess

 


data myGraph;
set sashelp.Citiday;
/* Weeks starting on a Sunday */
myDate = intck("DAY", "27DEC1987"d, date) / 7; 
format mydate z3.0;
run;

proc sgplot data=myGraph;
series x=mydate y=SNYDJCM;
xaxis integer label="Week Number";
run;
PG
Ask a Question
Discussion stats
  • 4 replies
  • 496 views
  • 0 likes
  • 4 in conversation