BookmarkSubscribeRSS Feed
OS2Rules
Obsidian | Level 7

Hi again:

I have been using regression on a GPLOT to project data into our next fiscal year (how time flies...)

I've seen that the regression equation is noted in the log of the job.

My client would like me to determine the actual data points for each month of next year to "add value" to the line on the graph.

Problem is that we have not licenced any STAT products (basically just SAS BASE) so I can't do it that way.

Is there a way that I can capture the values in the regression equation from the GLPOT and use them to make the calculations?  I would rather have an automated source because I have a boat load of graphs that are produced.  I could just drop the date values into the equation (with a DO loop to span the next year) and get the plot points.

Is this even possible?  I would rather not have to run the graphs, pull the data from the logs and then run another job to create the monthly values.

Thanks in advance.

9 REPLIES 9
GraphGuy
Meteorite | Level 14

Here's a small sample showing how to use gplot's built-in regression line, if anybody wants to use it to experiment and try to find a solution to OS2Rules' question...

symbol1 value=dot cv=red interpol=rl ci=blue;

proc gplot data=sashelp.stocks;
by stock;
plot close*date=1 / regeqn;
run;

Tom
Super User Tom
Super User

You could see if PROC GPLOT has any ODS output datasets by using ODS TRACE statement.

Otherwise you could fall back to the old method of redirecting the log to a file and reading it with a datastep.

filename templog temp;

proc printto log=templog;

run;

proc gplot

...

run;

quit;

proc printto log=log;

run;

data _null_;

   infile templog ;

   input @;

* put a copy of the log back into the real log ;

   put _infile_ ;

   .... look for the regression results ...

run;

DanH_sas
SAS Super FREQ

Unfortunately, GPLOT will not give you the regression points through ODS OUTPUT; however, SGPLOT will.  The examples below show both a regression fit and a loess fit. Some of the parameters for these fits can also be adjusted in the procedure. You need at lease SAS 9.2 to run them.

Hope this helps!

Dan

ods output sgplot=regdata;
proc sgplot data=sashelp.stocks;
by stock;
reg y=close x=date / clm;
run;
quit;

ods output sgplot=loessdata;
proc sgplot data=sashelp.stocks;
by stock;
loess y=close x=date / clm;
run;
quit;

Reeza
Super User

I'm assuming you need the formula, not the data points but you can also manually calculate the slop and intercept using proc means and a bunch of their precalculated statistics without too much work. SInce you're applying this to a predicted dataset at some point you'll need a datastep anyways.

OS2Rules
Obsidian | Level 7

Reeza:

The formula is provided by the GPLOT - or rather by the interpolation method.  I would like to "pick up" these values and plug in my future dates to get the data points.

Reeza
Super User

I know, but that involves scanning the log, it isn't stored somewhere. Also the log doesn't specify the by group the formula is for when you have multiple groups, or at least mine didnt (SAS 9.2.3).

So since you're going to have to grab it somehow, you can either scan the log as Tom has mentioned above or calculate it elsewhere, ie using the manual calculations in Proc Corr (not means like I said earlier). 

I'd personally prefer to calculate it elsewhere b/c the log doesn't specify which formula goes with which group/stock/by variable rather than read the log, but that's my preference. 

The formula's are below and all the outputs required (ie mean/std/correlation) will be outputted from Proc Corr which is available in base.

http://en.wikipedia.org/wiki/Simple_linear_regression

OS2Rules
Obsidian | Level 7

Dan:

This whole exercise started when SAS Institute told me that I could not use regression on a SGPLOT - which is what I was doing in the first place.  They said that the only interpolation that could be used is "JOIN", which is of no help.

I had a SGPLOT with a histogram (VBAR chart) and a "line" overlayed - I wanted to use regression on the line.

Perhaps it's because I'm still on 9.1.3 ....

Rick_SAS
SAS Super FREQ

Two comments:

1) Statistically speaking, I'd be careful about using linear regression to extrapolate. In general, use regression to interpolate, and use time series forecasting to extrapolate.

2) If you decide to procede, there is still some work to do. Dan Heath's method will give you the points in the plot. However, you'll have to use two of those points to find the slope-intercept formula for the line of best fit. Once you have the equation, you can fit new points by using the DO loop technique that you mentioned in your post.

Good luck,

Rick

OS2Rules
Obsidian | Level 7

Rick:

As it turns out, the regression is quadratic - here is what I see in the log:

WARNING: Least-square solutions for the parameters are not unique. QUADRATIC equation is used for the interpolation.

NOTE: Regression equation :  cost_per_rec =  18263.67 - 1.915098*date + 0.00005*date^2.

AS can be seen, the formula is there - I just need to plug in my future dates, and bingo!

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
  • 9 replies
  • 1433 views
  • 0 likes
  • 6 in conversation