Build the Create_report Frame

Adding to the Application

The second frame to build is the Create_report frame. This frame enables users to define the criteria for and then generate a report based on data in a SAS table.
Finished Create_report Frame
Finished Create_report Frame

Build the Graphical User Interface for the Create_report Frame

Create the Create_report frame by entering the following command at the SAS command line:
build sasuser.example.Create_report.frame
To create the graphical user interface for the frame, drag the following controls onto the frame and position them as you see in Finished Create_report Frame:
  • one Text Label Control
  • one Combo Box Control
  • two Radio Box Controls
  • two Push Button Controls
  • one External File Viewer Control
After dragging all the controls to the frame, your frame should resemble this:
Preliminary Create_report Frame
Preliminary Create_report Frame

Set Attribute Values for the Create_report Controls

Rename the controls so that they have meaningful names in the Properties window. These control names will be used as section labels in the SCL code that is added later.
In the Properties window, set the name attribute of each control as follows:
  • Combobox1 to YearCombobox
  • Radiobox1 to QuarterRadiobox
  • Radiobox2 to CountryRadiobox
  • Pushbutton1 to CreateRptButton
  • Pushbutton2 to CloseButton
  • Externalfileviewer1 to ReportViewer
To set the text of the banner at the top of the frame, set the following:
  • Textlabel1 font attribute to Arial, Regular, 16
  • Textlabel1 label attribute to Sales Reports
Resize the Textlabel1 control to make the larger text display correctly.
To set the text for the controls that define the report criteria, set the following:
  • YearCombobox borderStyle attribute to Simple
  • YearCombobox borderTitle attribute to Year
  • QuarterRadiobox borderTitle attribute to Quarter
  • CountryRadiobox borderTitle attribute to Country
To add text and an icon to the CreateRptButton, set the following:
  • buttonStyle attribute to Icon with Text to Right
  • icon attribute to 296
  • label attribute to Create Report
Resize the CreateRptButton to make the icon and label display correctly.
To customize the CloseButton, set the following:
  • commandOnClick attribute to end;
    Note the semicolon at the end of the command.
  • height attribute to 30
  • label attribute to Close Window
  • width attribute to 80
To prevent the command line from appearing on the frame, set the frame bannerType attribute to None.
Lastly, set the items attribute on the YearCombobox so that the years 1993 and 1994 are available to the user. Follow these steps:
  1. Scroll to the YearCombobox items attribute.
  2. Click in the Value column.
  3. Click the ellipsis button in the Value column.
    The List Editor appears.
  4. Add the values 1993 and 1994.
  5. Exit the List Editor by clicking OK.
The List Editor
The List Editor
Lastly, enlarge the External File Viewer so that it is sized similarly to Finished Create_report Frame .

Attach Models to the Create_report Frame Controls

To associate the controls on the frame with the proper models, follow these steps:
  • Drop a Variable Values List Model onto the QuarterRadiobox.
    This Variable Values List Model is automatically named Variablevalueslist1.
    In the Properties window, set the following attributes on Variablevalueslist1:
    • dataset attribute to sashelp.prdsale
    • variable attribute to Quarter
  • Drop a Variable Values List Model onto the CountryRadiobox.
    This Variable Values List Model is automatically named Variablevalueslist2.
    In the Properties window, set the following attributes on Variablevalueslist2:
    • dataset attribute to sashelp.prdsale
    • variable attribute to Country
The two Radio Box controls should now have values in them.
Resize the controls on the frame if necessary. Sometimes the initial layout of the controls is not conducive to the data they present (for example, Radio Boxes that are too short for the data they contain). Expand the Radio Boxes vertically to make them resemble Finished Create_report Frame.

Add SCL Code to the Create_report Frame

Add the following code to the Create_report frame SCL. After adding the code, save it and then close the frame SCL window.
/* This is the frame SCL for the Create_report frame. */
/*                                                    */
/* The user selects a year, a quarter, and a country, */
/* and then clicks the CreateRptButton. Data that     */
/* matches the user selections is pulled from         */
/* SASHELP.PRDSALE, written to a file, and then       */
/* displayed in the External File Viewer.             */

dcl num rc; /* Numerical variable used as a return code. */
dcl list messageList={}; /* Creates an empty list. */

dcl char(7) countryName,
    char(1) quarterValue,
    char(4) yearValue,
    char(2) command; /* Declare character variables. */
     
INIT:
   /* Define a warning message. */
   rc=insertc(messageList, 'To create the report, please ' ||
              'select values for year, quarter, and country.');

   /* Assign a fileref to an external file. */
   rc=filename('out', ' ', 'temp');

   /* Turn off 'End of file' message. */
   ReportViewer._showEndOfFile('no');
return;

/* Executes when you click on the CreateRptButton */
CreateRptButton:
   /* If a fileref is already assigned to ReportViewer, clear the fileref. */ 
   if ReportViewer.fileref ne ' ' then ReportViewer.fileref=' ';

   /* Initialize variables with user selections. */
   countryName = CountryRadiobox.selectedItem;
   yearValue = YearCombobox.selectedItem;
   quarterValue = left(QuarterRadiobox.selectedItem);

/* If all criteria have been selected, create a report . */
   if countryName ne ' ' and 
      yearValue ne ' ' and
      quarterValue ne ' ' then
   do;
      submit continue;

         /* Close the default ODS destination. */
         ods html close; 

         /* Enable the ODS listing destination. */ 
         ods listing device=listing; 

         /* Redirect SAS output to the temp file. */
         proc printto print=out new;

         /* Suppress printing the PROC title. */
         ods noproctitle;

         /* Set options to control procedure output. */
         options nodate nonumber nocenter;

         /* Create a summary report of the PRDSALE table using */
         /* selected values for Country, Year, and Quarter.    */
         proc means data = sashelp.prdsale nonobs sum;
            where country = '&countryName' and
                  year = &yearValue and
                  quarter = &quarterValue;
            class product;
            var predict actual;
            title1 'Sales Figures for &countryName: ';
            title2 'Quarter &quarterValue in &yearValue';
         run;      
   
         /* Redirect SAS output back to the default location. */
         proc printto;
         run;

         /* Reset options that control procedure output. */
         options date number center;
      endsubmit;
      ReportViewer.fileref = 'out';
   end;

   /* If a criteria was not selected, display a warning dialog. */
   else command = messagebox(messageList, '!', 'O', 
                           'Application warning message');
return;

TERM:
   /* Delete the SCL list. */
   messageList=dellist(messageList);

   /* Clear the fileref assigned to ReportViewer. */
   ReportViewer.fileref=' ';

   /* Clear the fileref OUT. */
   rc=filename('out', ' ');
 return;
Note: In SAS 9.3 the default output, known as the destination, in the SAS Windowing environment was switched to HTML. Because the External File Viewer control used in this example cannot display HTML, the code above includes statements to disable the HTML destination and enable the listing destination.

Compile the Create_report Frame

To compile the Create_report frame, make sure it is the active window, and then select Buildthen selectCompile.
If the frame and SCL code compiled successfully, you should see messages similar to these in the Log window:
NOTE: Compiling CREATE_REPORT.FRAME (SASUSER.EXAMPLE.CREATE_REPORT.SCL).
NOTE: Code generated for CREATE_REPORT.FRAME. Code size=4095.
To view the Log window, select Viewthen selectLog.
You should correct all warnings and errors.

Test the Create_report Frame

Although you tested the previous frame, Display_data, with the Buildthen selectTest menu command, the Create_report frame is different because its frame SCL code contains a SUBMIT block.
The command that is run to execute a frame when you select Buildthen selectTest is not capable of running SUBMIT blocks. If you try to test the Create_report frame using the Buildthen selectTest menu command, the program will generate a run-time error when you click the Create Report button. Instead, you must test this frame from outside the SAS/AF build environment.
To run the Create_report frame from a SAS Explorer window, follow these steps:
  1. Close the Create_report frame.
  2. Click the Explorer tab (in the lower-left corner of the main SAS window).
  3. Navigate to the Create_report frame (inside SASUSER.Example).
  4. Right-click the Create_report frame, and then select Run.
When the frame is running, test it by selecting a Year, a Quarter, and a Country, and then clicking the Create Report button.
Completed Create_report Frame
Completed Create_report Frame
If you look in the Log window while the report is being created, you can see the SUBMIT block commands running.
Close all the Create_report frames after you have finished testing.