Data visualization with SAS programming

Multiple plots with different vertical bars

Reply
Frequent Contributor
Posts: 124

Multiple plots with different vertical bars

Hello,

TimeSerie1.png

proc sgplot data=_5A;

  pbspline x=Date y=max / nomarkers lineattrs=(color=cxB30000) legendlabel="Maximum";

  pbspline x=Date y=q3 / nomarkers lineattrs=(color=cxE34A33) legendlabel="3rd quantile";

  pbspline x=Date y=median / nomarkers lineattrs=(color=cxFC8D59) legendlabel="Median";

  pbspline x=Date y=q1 / nomarkers lineattrs=(color=cxFDCC8A) legendlabel="1st quantile";

  pbspline x=Date y=min / nomarkers lineattrs=(color=cxFEF0D9) legendlabel="Minimum";

  keylegend / noborder position=top location=inside across=1;

  ;run;quit;

This is a time series plot of different values at 20 different dates.

I would like to create 20 different versions of this same plot, each time with one vertical line at the 20 different dates.

SAS Super FREQ
Posts: 3,236

Re: Multiple plots with different vertical bars

First, depending on what you are trying to model, you might want to consider quantile regression. See Quantile regression: Better than connecting the sample quantiles of binned data - The DO Loop

To answer your question, you could use the SGPANEL procedure with DATE as the PANELBY variable and the orginal (unsummarized) data as the Y variable.

However, you should also consider whether a single plot might suffice.  A scatter plot of DATE vs "original Y variable" might give you what you want. An example is in the article that I linked to earlier.  Alternatively, to get an easy summarization, you might want to create a VBOX of the original Y variable with CATEGORY=DATE.

Frequent Contributor
Posts: 124

Re: Multiple plots with different vertical bars

Like this for '01jan2012'd

TimeSerie1.png

SAS Super FREQ
Posts: 864

Re: Multiple plots with different vertical bars

You can use SGPLOT with a BY-group to generate the 20 plots; but, instead of using a literal value for the REFLINE, use a variable that contains the reference line values. That way, the reference line position will vary per BY-group.

Hope this helps!
Dan

Frequent Contributor
Posts: 124

Re: Multiple plots with different vertical bars

Hi,

Thanks for the replies.

- Quantile regression: I don't think this is appropriate for what I intend to do.

- SGplot with by-group does not work. I think it's becasue there is only one date to plot, and then "pbspline x=Date y=max" will not produce any graph.

This produces the intended result, do you think it's efficient ?

%macro krigetimeplot(date);

  proc sgplot data=_5A;

  pbspline x=Date y=max / nomarkers lineattrs=(color=cxB30000) legendlabel="Maximum";

  pbspline x=Date y=q3 / nomarkers lineattrs=(color=cxE34A33) legendlabel="3rd quantile";

  pbspline x=Date y=median / nomarkers lineattrs=(color=cxFC8D59) legendlabel="Median";

  pbspline x=Date y=q1 / nomarkers lineattrs=(color=cxFDCC8A) legendlabel="1st quantile";

  pbspline x=Date y=min / nomarkers lineattrs=(color=cxFEF0D9) legendlabel="Minimum";

  keylegend / noborder position=top location=inside across=1;

  refline &date / axis=x;

  ;run;quit;

%mend krigetimeplot;

data _null_; set _5A;

  call execute('%krigetimeplot('||Date||')');

  run;

Post a Question
Discussion Stats
  • 4 replies
  • 313 views
  • 0 likes
  • 3 in conversation