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,445

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.

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags