BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Daniel
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

@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

3 REPLIES 3
PGStats
Opal | Level 21

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
Jeff_Perkinson
Community Manager

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

Rick_SAS
SAS Super FREQ

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

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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