User-Defined Reports

Overview of User-Defined Reports

User-defined reports require the following files to be uploaded to the SAS Content Server:
  • the SAS program that creates the report
  • a SAS program file that lists the SAS Model Manager global macro variables that are used in your report
  • a report template XML file that specifies the report requirements, such as report name and the number of required models to run the report
After these three files have been uploaded to the SAS Content Server, the user-defined report type is included as a report in the New Reports Wizard Reports list.
Inherent in the New Report Wizard are controls to specify the type of output that the report creates, such as HTML or PDF. You can modify your report to include the SAS code so that the New Report Wizard offers the report output controls for your report.

Create a User-Defined Report

Write your SAS program to create a report. Include in your program the code modifications to support output formats.
To format the output for a user-defined report, add the SAS code below to your report code in order to use the Select Formats list box in the New Report Wizard. The Select Formats list box enables you to select a report output format of HTML, PDF, RTF, or Excel.
Replace report-name with the name of your user-defined report. End your user-defined report with the %MM_ExportReportsEnd macro.
Filename mmreport catalog "sashelp.modelmgr.reportexportmacros.source";
%include mmreport;
%MM_ExportReportsBegin(fileName=report-name);
          …
   your-user—defined-code
          …
%MM_ExportReportsEnd;
In the report XML file, add this SAS program name to the <Code filename=" "> argument. For example, <Code filename="myUserReport.sas"/>. See The Report Template.
For an example of a report, see Example User-Defined Report.

Defining SAS Model Manager Macro Variables for a User-Defined Report

Executing a user-defined report requires a SAS program that lists the report code’s SAS Model Manager macro variables. If you do not have SAS Model Manager macro variables in your report, create a SAS program file with a comment in it. This file is required.
Here is an example program to define macro variables:
%let _MM_User=miller;
%let _MM_Password=Rumpillstillskin3;
In the report XML file, add this SAS program name to the <PreCode filename= " "> element. For example, <PreCode filename="myMacroDefs.sas"/>. See The Report Template.
For an example of a SAS Model Manager macro variable programs, see Example User-Defined Report.
For a list of SAS Model Manager macro variables, see SAS Model Manager Macro Variables.

Upload SAS Programs to the SAS Content Server

After you have the two SAS programs for your user report, follow these steps to upload them to the SAS Content Server:
  1. Select Toolsthen selectManage Templates to open the SAS Model Manager Template Editor.
  2. Select Filethen selectOpen, select the program in the Open window, and click OK.
  3. Select Filethen selectUpload File to upload the program to the SAS Content Server.
  4. Repeat steps 2 and 3 to upload the second file.

The Report Template

You create a report template XML definition file to describe your user-defined report. After you create the report template, upload the template to the SAS Content Server.
SAS Model Manager provides a sample report template that you can use as a model for your XML template. You can use any template as a model or you can create an XML file with the required XML elements. A best practice is to open the model XML template and save the template using another name. To open a sample report template, follow these steps:
  1. Select Toolsthen selectManage Templates to open the SAS Model Manager Template Editor.
  2. Select Filethen selectBrowsethen selectBrowse Templates. Select UserReportTemplate.xml and click OK.
  3. Select Filethen selectSave As. Type a name in the File name field and click OK.
  4. The UserReportTemplate.xml file has arguments in quotation marks that you modify for your report. Replace the text in quotation marks with values that are appropriate for your report. See the argument descriptions below.
  5. When the report template is complete, select Filethen selectUpload File to upload the report template to the SAS Content Server.
Here is the report template XML definition:
<?xml version="1.0" encoding="UTF-8" ?>
<ReportTemplate 
	name="report-name" 
	type="UserDefinedReport"
	displayName="display-name" 
	description="model-description"
	>
	<Report>
		<Data datasetName="input-data-set-name"/>
		<Models expectedModelType="model-type" 
           requiredNumberOfModels="1" 
           level="level">
   </Models>
		<SourceCode>
			<PreCode filename="pre-code-filename.sas"/>
			<Code filename="score-code-filename.sas"/>
		</SourceCode>
		<Output format="output-format" filename="output-name"/>
	</Report>
	<Parameters>
		<Parameter name="parameter-name" value="parameter-value" />
	</Parameters>
</ReportTemplate>
<ReportTemplate> element arguments
name="report-name"
specifies the name of the report. The characters @ \ / * % # & $ ( ) ! ? < > ^ + ~ ` = { } [ ] | ; : ‘ " cannot be used in the name.
displayName="display-name"
specifies the name of the report that is displayed in the Reports list of the New Reports Wizard window.
description="model-description"
specifies a description of the report that displays at the bottom of the New Reports Wizard when the report is selected in the window.
<Report> element arguments
<Data datasetName="input-data-set-name"/>
specifies the name of a data source data set that is used for input to the report. The data set must be in the form libref.filename. You can use the following global macro variables as a value for input-data-set-name as long as the value of the macro variable is in the form of libref.filename:
  • &_MM_InputLib
  • &_MM_OutputLib
  • &_MM_PerformanceLib
  • &_MM_TestLib
  • &_MM_TrainLib
<Models
expectedModelType="model-type"
requiredNumberOfModels="number-of-models"
level="level">
</Models>
specifies information about the model.
expectedModelType="model-type"
specifies the model type.
Valid values: ANALYTICAL, CLASSIFICATION, PREDICTION, SEGMENTATION, ANY
requiredNumberOfModels="number-of-models"
specifies the number of models that are processed in this report.
level="folder"
specifies where the report is to obtain a list of models. If folder is VERSION, the report creates a list of models in the version. If folder is PROJECT, the report creates a list of models from all versions in the project.
Valid values: VERSION, PROJECT
<SourceCode>
<PreCode filename="pre-code-filename.sas"/>
<Code filename="report-code-filename.sas"/>
</SourceCode>
specifies the files that are used to execute the report.
<PreCode filename="pre-code-filename.sas"/>
specifies the name of the SAS program that contains macro variable definitions.
<Code filename="report-code-filename.sas"/>
specifies the name of the SAS program that creates the report.
<Output format="output-format" filename="output-report-name"/>
specifies the output format arguments:
format="output-format"
specified the format of the report output.
Valid values: HTML, PDF, RTF, or Excel
filename="output-report-name"
specifies the name of the output report.
<Parameters> Element Argument
<Parameter name="parameter-name" value="parameter-value" />
This element is not used. It is reserved for future use.

Edit a SAS Program on the SAS Content Server

To edit the program after the file has been uploaded to the SAS Content Server, follow these steps:
  1. Select Filethen selectBrowsethen selectBrowse SAS Files.
  2. Select the program and click Open.
  3. Modify the program. When you have finished making changes, upload the file to the SAS Content Server by selecting Filethen selectUpload File.
  4. (Optional) To save a backup of the template, from the Browse Templates window, select Filethen selectSave As. Select a file location, enter a filename, and click Save.

Delete a SAS Program from the SAS Content Server

To delete a SAS program from the SAS Content Server, follow these steps:
  1. Select Filethen selectBrowsethen selectBrowse SAS Files.
  2. Select the program and click Delete.

Run a User-Defined Report

To run a user-defined report, follow these steps:
  1. Expand the version folder Version Icon.
  2. Right-click the Reports node and select Reportsthen selectNew Report Wizard. The New Report Wizard window appears.
  3. From the Reports list box, select a user-defined report.
  4. In the Select Model(s) box, select the appropriate model or models for the report.
  5. In the Select Format list box, select the type of output that you want to create. The default is PDF. Other options are HTML, RTF, and Excel.
  6. In the Report Properties box, enter a report name or use the default report name. The default report name is in the form report-name_DdateTtime.
  7. Click OK. The report runs, a report folder is created, and the output is stored in the report folder. The name of the report folder is the report name that you specified in the Report Properties box.

View a User-Defined Report

To view a user-defined report, right-click the report name under the Reports node and select Reportsthen selectView Report.

Example User-Defined Report

Overview of the Example User-Defined Report

The example user-defined report categorizes scoring values into score ranges and then graphs the results. The program name is Score Range Report. The following SAS programs and report template file are required to create this report:
  • The SAS report program is the file ScoreRange.sas
  • The SAS program file that contains macro variables is ScoreRangeMacro.sas
  • The report template XML file is ScoreRangeTemplate.xml

The SAS Report Program

Here is the SAS code for a user-defined report to categorize score codes:
filename mmreport catalog "sashelp.modelmgr.reportexportmacros.source";
%include mmreport;

%MM_ExportReportsBegin(fileName=scoreRange);

options NOmprint;
%let _MM_PosteriorVar=P_1;


proc format;
  value score
    low - 400 = '400 and Below'
    401 - 450 = '401 - 450'
    451 - 500 = '451 - 500'
    501 - 550 = '501 - 550'
    551 - 600 = '551 - 600'
    601 - 650 = '601 - 650'
    651 - 700 = '651 - 700'
    701 - 750 = '701 - 750'
    751 - 800 = '751 - 800'
    801 - high= '801 and Above';
run;
quit;

%Macro scoreRange();

  %if &_MM_ScoreCodeType = %str(SAS Program) %then
    %do;
       %let _MM_OutputDS=work.scoreresult;
       %inc &_MM_Score;
    %end;
  %else
    %do;
       data work.scoreresult;
       set &_MM_InputDS;
       %inc &_MM_Score;
       run;
    %end;

  data work.scoreresult2;
    set work.scoreresult;
    keep score;
    if &_MM_PosteriorVar =. then delete;
    score = int (((1-&_MM_PosteriorVar) * 480) + 350 + 0.5);
  run;

  proc freq data=work.scoreresult2;
    table score/out=scoresummary;
    format score score.;
    title 'Credit Score Range';
  quit;

  proc gchart data=work.scoresummary;
    hbar score / sumvar=count discrete;
    title 'Credit Score Range';
  run;
  quit;
%Mend scoreRange;

/*   Reporting section */

ods listing close;

%getModelInfo(0);
%scoreRange();
%closeLibsAndFiles();

%MM_ExportReportsEnd;

The SAS Program File for Macro Variables

The file ScoreRangeMacro.sas contains only a comment in it because macro variables are not used in the report code:
/* ScoreRangeMacro.sas empty file   */

The Report Template XML File

Here is the report template XML file for the user-defined Score Range report:
<?xml version="1.0" encoding="UTF-8" ?>
<ReportTemplate 
	name="Score Range Report" 
	type="UserDefinedReport"
	displayName="Score Range Report" 
	description="Score Range Report"
	>
	<Report>
		<Data datasetName=""/>
		<Models expectedModelType="ANALYTICAL" 
           requiredNumberOfModels="1" level="VERSION">
		</Models>
		<SourceCode>
			<PreCode filename="ScoreRangeMacro.sas"/>
			<Code filename="ScoreRange.sas"/>
		</SourceCode>
		<Output format="PDF" filename="ScoreRange"/>
	</Report>
	<Parameters>
	</Parameters>
</ReportTemplate>

The Score Range Report Output

The following Credit Score Range graph is one of the output pages in the PDF report output:
Credit Score Range Graph Taken From the Output Report PDF File