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-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!

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.

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
  • 3 replies
  • 6094 views
  • 5 likes
  • 4 in conversation