Help using Base SAS procedures

Graph a mathematical function

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Graph a mathematical function

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 Smiley Happy


Accepted Solutions
Solution
‎02-24-2016 11:43 AM
SAS Super FREQ
Posts: 3,476

Re: Graph a mathematical function

@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));

View solution in original post


All Replies
Respected Advisor
Posts: 4,644

Re: Graph a mathematical function

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
Community Manager
Posts: 1

Re: Graph a mathematical function

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
SAS Super FREQ
Posts: 3,476

Re: Graph a mathematical function

@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));

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 310 views
  • 5 likes
  • 4 in conversation