BookmarkSubscribeRSS Feed

Asked & Answered: How to create plots in the SAS Code node in Model Studio

Started ‎02-20-2019 by
Modified ‎02-22-2019 by
Views 1,616

Question

97403_banner_Asked&Answered_aqua.pngHow can I create plots, such as a bar chart, in the SAS Code node in Model Studio?

Answer

Here are some examples of how you would create a series plot, bar chart, pie chart, and band plot in a SAS Code node in Model Studio, using whatever data that you create or reference in the node in the &dm_lib library (just replace the name exampData with your name, and the actual data with the data you want to use).  

 

 

/* SAS code */

data &dm_lib..exampData;
     a = "a";  b = 2; c=1; d=3; x=3;
     output;

     a = "b";  b = 5; c=4; d=9; x=5;
     output;

     a = "c";  b = 4; c=2; d=5;  x=10;
     output;
run;

/* Series Plot  */
%dmcas_report(dataset=exampData, reportType=SeriesPlot, x=a, y=b, description=%nrbquote(Series Plot), yref=3);

/* Bar Chart  */
%dmcas_report(dataset=exampData, reportType=BarChart, category=a, response=b,description=%nrbquote(Bar Chart));

/* Bar Chart - sorted X-axis */
%dmcas_report(dataset=exampData, reportType=BarChart, category=a, response=b, sortBy=b, description=%nrbquote(Bar Chart - Sorted));

/* Pie Chart */
%dmcas_report(dataset=exampData, reportType=PieChart, category=a, response=b, description=%nrbquote(Segment Plot));

/* Band Plot  */
%dmcas_report(dataset=exampData, reportType=BandPlot, x=x, y=b, limitLower=c, limitUpper=d, description=%nrbquote(Band Plot));

 

Here’s an example for creating a scatter plot of Residuals by Predicted in a SAS Code node following a Supervised Learning node for an interval target:

 

/* SAS code */

data &dm_lib..samp;
      set &dm_data(obs=200);
      Residual = Target - P_Target; /* substitute "Target" with the name of your target variable */
run;

%dmcas_report(dataset=samp, reportType=ScatterPlot, x=P_Target, y=Residual, description=%nrbquote(Scatter Plot), yref=0);

 

These code examples are also available from this GitHub repository.

Contributors
Version history
Last update:
‎02-22-2019 01:13 PM
Updated by:

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags