BookmarkSubscribeRSS Feed
KageKitsune28
Calcite | Level 5

I have 10 data points representative of years (2003-2012).  I would like to show the regression line for the first 8 points (2003-2010) and have the last two points stand alone.  Is it possible to accomplish this with GPlot?

8 REPLIES 8
Jay54
Meteorite | Level 14

Easily done with SGPLOT.  Move the last two points to new columns  (x2, y2) and make them missing in the original columns (x, y).  Now plot a regressioin plot using original columns (x, y).  Overlay a scatter plot with new columns (x2, y2).

KageKitsune28
Calcite | Level 5

Great!  I am going to try that. Smiley Happy Thank you!

KageKitsune28
Calcite | Level 5

Well this was working great until I added the regression line.  The regression line is stretching across all 10 points instead of stopping at 8.

GraphGuy
Meteorite | Level 14

Are you using gplot, or sgplot?

GraphGuy
Meteorite | Level 14

The built-in gplot interpol=rl regression line is going to always go all the way to the axis (I think).

If you just want the regression line to go to a certain point (and not all the way to the axis), then I think you'll need to calculate the points along the regression line (such as using Proc Reg), and then plot those points using interpol=join.

Jay54
Meteorite | Level 14

Or, just use SGPLOT.  Smiley Happy

data fit;
  do x2=1 to 8;
    y2=10+2*rannor(2); output;
  end;
  x2=.; y2=.;
  do x=9 to 10;
    y=10+2*rannor(2); output;
  end;
run;

proc sgplot data=fit;
  reg x=x2 y=y2 / name='r';
  scatter x=x y=y;
  keylegend 'r';
  run;

GraphGuy
Meteorite | Level 14

Similar to what Sanjay was saying about sgplot, you could also do this with gplot.

See the 'Forecast Line' example, near the middle of this Line Plot chapter for an example:

http://robslink.com/SAS/book1/Chapter_02_Lines.pdf

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
  • 8 replies
  • 1208 views
  • 6 likes
  • 3 in conversation