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
- /
- SAS Procedures
- /
- Graph a mathematical function

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

02-09-2016 11:34 AM

Dear All,

Aside from simulating data in a data step and then use a procedure such as PLOT, GPLOT, SGPLOT, etc. is there any way to graph a mathematical function (say y = x**2) by simply inputting the function and requesting a graph?

For me, the go-to method was the above, i.e. simulate the data first and then plot it, but I thought there might be some function out there (or something in either EG or IML Studio perhaps) that would do the trick.

Thank you for your input

Accepted Solutions

Solution

02-24-2016
11:43 AM

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

02-10-2016 08:39 AM

@PGStats shows the usual method. Since you mentioned IML, I'm thinking that perhaps your function is defined by a function module? If so, you can use a similar approach from inside SAS/IML:

proc iml; start MyFunc(x); return( x##2 ); finish; t = do(-2, 2, 0.1); call series(t, MyFunc(t));

From inside SAS/IML Studio you can get an interactive plot by using

LinePlot.Create("function plot", t, MyFunc(t));

All Replies

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

02-09-2016 01:25 PM

Took me about 30 seconds to write

```
data function;
do x = -1 to 4 by 0.05;
y = x**2;
output;
end;
run;
proc sgplot data=function;
series x=x y=y;
run;
```

and get a decent basic graph. SAS software (GTL, SG, SAS/GRAPH, even JMP) doesn't graph user-specified functions, only data.

PG

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

02-12-2016 04:35 PM

Just to clear up a misconception, JMP will plot functions.

See the Formula Element in Graph Builder or for more flexibility the Y Function() in graphic scripting.

For functions in more than two dimensions the various Profilers in JMP offer the ultimate flexibility.

-Jeff

Solution

02-24-2016
11:43 AM

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

02-10-2016 08:39 AM

@PGStats shows the usual method. Since you mentioned IML, I'm thinking that perhaps your function is defined by a function module? If so, you can use a similar approach from inside SAS/IML:

proc iml; start MyFunc(x); return( x##2 ); finish; t = do(-2, 2, 0.1); call series(t, MyFunc(t));

From inside SAS/IML Studio you can get an interactive plot by using

LinePlot.Create("function plot", t, MyFunc(t));