BookmarkSubscribeRSS Feed
mathias
Quartz | Level 8

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.

4 REPLIES 4
Rick_SAS
SAS Super FREQ

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.

mathias
Quartz | Level 8

Like this for '01jan2012'd

TimeSerie1.png

DanH_sas
SAS Super FREQ

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

mathias
Quartz | Level 8

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 4 replies
  • 982 views
  • 0 likes
  • 3 in conversation