turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Looking for a way to programmatically identify "th...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-25-2013 12:50 PM

I have a GPLOT that creates two lines (curves) for each of two test series. I want to be able to identify "the knee of the curve" for each curve through code rather than the usual visual approximation.

There is no real definition of "knee of the curve" but I am thinking it would be the first point in which the line between two adjacent values of the 'X' axis has a slope of 1.

I would like to have that point highlighted in some way on each line.

Any suggestions?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to lloydc

04-25-2013 01:26 PM

To say that the slope is 1 means the tangent line to the curve is at a 45 degree angle. In high school geometry terms, rise=run. Thus

the distance between the adjacent x's is equal to the distance between the adjacent y's. You should be able to find that point using LAG variables and a DATA step. Once you have found it, you can create an annotate data set to label the location on the graph.

Using the ANNOTATE facility is a bit clumsy, but I think that is what you would have to do using GPLOT. If you have a more recent version of SAS (9.3, especially), you could use SGPLOT and label or highlight sections much more easily. If you've never used the SG plotting capability, check out the Graphically Speaking blog for lots of good examples ( Graphically Speaking - Data Visualization with a focus on SAS ODS Graphics ).

Doc Muhlbaier

Duke

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to lloydc

04-25-2013 02:53 PM

This is the outline of how you could create that graph with SGPLOT (untested) :

**proc sort data=myData; by series x; run;**

**data myGraph;**

**retain kneeFound 0;****set myData;****by series;****if first.series then kneeFound = 0;**

**else kneeFound = kneeFound or dif(y) >= dif(x);****nbOverKnee + kneeFound;****if nbOverKnee = 1 then**** yK = Y;**

**run;**

**proc sgplot data=myGraph;****series x=x y=y / group=series;****scatter x=x y=yK / group=series;****run;**

You could omit the group= option in the scatter statement if you wanted both knees to be identified with the same symbol.

PG

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PGStats

04-28-2013 04:25 PM

Just wanted to say thanks. I haven't tried this yet but it looks viable.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to lloydc

04-28-2013 09:15 PM

I took the time to do some testing and found some snags :smileyangry: ! So here is a better alternative:

**data myData;****series = 1;****do x = 0 to 1 by 0.05;**** y = x**2;**** output;**** end;****series = 2;****do x = 0 to 1 by 0.05;**** y = x**3;**** output;**** end;****run;**

**proc sort data=myData; by series x; run;**

**data myGraph;****retain kneeFound;****length yText $20;****set myData;****by series;****aboveKnee = dif(y) > dif(x);****if first.series then kneeFound = 0;**

**else do;**** if not kneeFound and aboveKnee then do;**** yK = Y;**** yText = catt("x=",x," y=",y); /* In case you need a label */**** end;**** kneeFound = kneeFound or aboveKnee;**

** end;****run;**

**proc sgplot data=myGraph;****series x=x y=y / group=series;****scatter x=x y=yK / group=series datalabel=yText;****run;**

and here is the resulting graph

PG

PG