statguru

profilestrength
week5-week10.zip

Data managment weeks/week 10/Proc PMENU.pptx

Data Management and Business Intelligence 5CC519

www.derby.ac.uk/engtech

Lecture 10 – Creating Menus in SAS

Dr John Panneerselvam

College of Engineering and Technology, University of Derby

Sensitivity: Internal

1

Contents

Pmenu - Overview

Syntax

Creating Menu

Associating Menu

‹#›

Sensitivity: Internal

2

Overview

Pmenu can be used in any SAS application

Menu needs to be activated first

SAS either processes a command, displays a menu or a submenu, or requests that you complete information in a dialog box

Dialog box is simply a box of questions or choices

The PMENU procedure produces no immediately visible output.

It simply builds a catalog entry of type PMENU that can be used later in an application

‹#›

Sensitivity: Internal

3

An Example

‹#›

Sensitivity: Internal

4

TAG_Audio:

TAG_Instructor:

TAG_Movie:

TAG_Print:

TAG_Section:

Syntax

PROC PMENU <CATALOG=<libref.>catalog>

MENU menu-bar;

ITEM command<option(s)>;

ITEM 'menu-item' <option(s)>;

DIALOG;

CHECKBOK;

RADIOBOX;

RADIOBUTTON;

MENU pulldown;

SELECTION;

SEPERATOR;

SUBMENU;

run;

‹#›

Sensitivity: Internal

5

Options

‹#›

Sensitivity: Internal

6

Proc PMENU STATEMENT

PROC PMENU <CATALOG=<libref.>catalog> ;

Specifies the catalog in which you want to store PMENU entries

The catalog will be saved in the specified library

Omitting the libref, catalog will be saved in the SASUSER library

proc pmenu catalog=proclib.menucat;

Proclib – libref

Catalog - menucat

‹#›

Sensitivity: Internal

7

MENU STATEMENT

MENU menubar;

names the catalog entry that stores the menus

MENU pulldown menu;

names the menu that appears when the user selects an item in the menu bar

ITEM STATEMENT

ITEM command <option(s)><action-options>;

a single word that is a valid SAS command for the window in which the menu appears

ITEM 'menu-item' <option(s)><action-options>;

a word or text string, enclosed in quotation marks, that describes the action that occurs when the user selects this item

‹#›

Sensitivity: Internal

8

ITEM Statement - Tasks

‹#›

Sensitivity: Internal

9

Example: MENU and ITEM Statements

proc pmenu cat=proclib.mycat;

menu windows; /* create catalog entry */

item 'Primary windows' menu=prime;

item 'Other windows' menu=other;

menu prime; /* create first menu */

item output;

item manager;

item log;

item pgm;

menu other; /* create second menu */

item keys;

item help;

item pmenu;

item bye;

run;

‹#›

Sensitivity: Internal

10

DIALOG Statement

DIALOG dialog-box 'command-string field-number-specification';

command-string

command or partial command that is executed when the item is selected

dialog-box

same name specified for the DIALOG= option in a previous ITEM statement

field-number-specification

order in which the contents appear

- @1...@n – text

- %1...%n - radiobox

- &1...&n - checkbox

‹#›

Sensitivity: Internal

11

DIALOG Statement – to know

Cannot control placement and size

Dialog box is not scrollable

To use the DIALOG statement, specify an ITEM statement with the DIALOG= option in the ITEM statement.

The ITEM statement creates an entry in a menu bar or in a menu, and the DIALOG= option specifies which DIALOG statement describes the dialog box.

You can use CHECKBOX, RADIOBOX, and RBUTTON statements to define the contents of the dialog box.

‹#›

Sensitivity: Internal

12

A typical Dialog Box

‹#›

Sensitivity: Internal

13

CHECKBOX Statement

CHECKBOX <ON> #line @column 'text-for-selection' <COLOR=color> <SUBSTITUTE='text-for-substitution'>;

column

specifies the column in the dialog box where the check box and text are placed

line

specifies the line in the dialog box where the check box and text are placed

text-for-selection

defines the text that describes this check box.

CHECKBOX must be used after a DIALOG statement

‹#›

Sensitivity: Internal

14

RADIOBOX Statement

RADIOBOX DEFAULT=button-number;

default

indicates which radio button is the default

RADIOBOX must be used after a DIALOG statement

RADIOBOC must be followed by one or more RBUTTON statements

‹#›

Sensitivity: Internal

15

RBUTTON Statement

RBUTTON <NONE> #line @column 'text-for-selection' <COLOR=color> <SUBSTITUTE='text-for-substitution'>;

column

specifies the column in the dialog box where the radio button and text are placed

line

specifies the line in the dialog box where the radio button and text are placed

text-for-selection

defines the text that appears in the dialog box.

RBUTTON must be used after a RADIOBOX Statement

‹#›

Sensitivity: Internal

16

SELECTION Statement

SELECTION selection 'command-string';

selection

same name specified for the SELECTION=

option in a previous ITEM statement

command-string

text string, enclosed in quotation marks, that is submitted as a command-line command when the user selects this item

SELECTION must be used after a ITEM Statement

Selection is used to associate an item with a selection option to define the command that executes when the user selects the item in the menu

‹#›

Sensitivity: Internal

17

SEPERATOR Statement

SEPERATOR;

Used to draw a line between the items listed in the menu

Must be used after an ITEM statement

‹#›

Sensitivity: Internal

18

SUBMENU Statement

SUBMENU submenu-name SAS-file;

Submenu-name

specifies a name for the submenu statement. To associate a submenu with a menu item, submenu- name must match the submenu name specified in the SUBMENU= action-option in the ITEM statement.

SAS-file

specifies the name of the SAS file that contains the common submenu

‹#›

Sensitivity: Internal

19

TEXT Statement

TEXT #line @column field-description <ATTR=attribute> <COLOR=color>;

column

specifies the starting column for the text or input field

Field-description

defines how the TEXT statement is used

LEN= user input

‘text’ string that appears

line

specifies the line number for the text or input field

Can be used only after a DIALOG statement

‹#›

Sensitivity: Internal

20

Steps in creating a Menu

Define the PMENU and the catalog in the proc PMENU statement

Define the menu statement to describe the menu and its catalog

Use the item statement to define the type of the entries (this can be menu, dialog, selection, submenu etc)

Describe each of the items in detail to customise their features

Associate the created menu with an application (this could be windows, FRAME, FSEDIT etc)

‹#›

Sensitivity: Internal

21

‹#›

Sensitivity: Internal

22

Associating a Menu with Proc FSEDIT

Data menu.menu; creates a simple menu option

format menuopt 1.;

run;

proc fsedit data=menu.menu screen = menu.menu;

run; associates the previous menu option

data _null_ ; calls in and executes the SAS code

set menu.menu; based on the menu option

if menuopt = 1 then call symput('choice', "'D:\Test\q1.sas’”);

else if menuopt = 2 then call symput('choice', "'D:\Test\q2.sas’”);

else if menuopt = 3 then call symput('choice', "'D:\Test\q3.sas’”);

run;

%include &choice; macro to run the choice in the

run; menu option

quit;

run;

Location of your SAS code

‹#›

Sensitivity: Internal

23

Associating a Menu with Proc FSEDIT

Data menu.menu;

format menuopt 1.;

run;

proc fsedit data=menu.menu screen = menu.menu;

run; screen prints the menu option listed in the menu.menu dataset

A simple menu option to enter your choice

‹#›

Sensitivity: Internal

24

Customize Proc FSEDIT Screen based on your questions

Edit the proc FSEDIT screen using F7 option while your are in the FSEDIT screen (to type your own questions and save it)

‹#›

Sensitivity: Internal

25

Editing the Proc FSEDIT screen

‹#›

Sensitivity: Internal

26

www.derby.ac.uk/engtech

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

Sensitivity: Internal

27

References

SAS Programming 1: Essentials- SAS Institute.

SAS: The Power to Know- Official documentation.

www.derby.ac.uk/engtech

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

Sensitivity: Internal

28

Data managment weeks/week 5/Lecture 5 Working with SAS Datasets.pptx

Business Analytics with SAS 7CS512

www.derby.ac.uk/engtech

Lecture 5 – Working with SAS Datasets

Dr John Panneerselvam

College of Engineering and Technology, University of Derby

Appending and Concatenating

Appending and concatenating involves combining SAS data sets, one after the other, into a single SAS data set.

2

+

Appending adds the observations in the second data set directly to the end of the original data set.

Concatenating copies all observations from the first data set and then copies all observations from one or more successive data sets into a new data set.

SAS Data Set
SAS Data Set

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

2

Appending and concatenating are very similar; it is bringing the data together vertically. Appending … Concatenating …

Merging

Merging involves combining observations from two or more SAS data sets into a single observation in a new SAS data set.

Observations can be merged based on their positions in the original data sets or merged by one or more common variables.

3

SAS Data Set
SAS Data Set

+

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

3

Merging involves bringing the data together side by side…

Example: Appending a Data Set

One data set is appended to a master data set.

4

Emps
First Gender HireYear
Stacey F 2006
Gloria F 2007
James M 2007
Brett M 2008
Renee F 2008
Emps2008
First Gender HireYear
Brett M 2008
Renee F 2008
Emps
First Gender HireYear
Stacey F 2006
Gloria F 2007
James M 2007

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

4

Here is a specific example of appending … Note that the first data set is growing, we aren’t actually creating a new data set.

Example: Concatenating Data Sets

Two data sets are concatenated to create a new data set.

5

EmpsFR
First Gender Country
Pierre M France
Sophie F France
EmpsAll1
First Gender Country
Lars M Denmark
Kari F Denmark
Jonas M Denmark
Pierre M France
Sophie F France
EmpsDK
First Gender Country
Lars M Denmark
Kari F Denmark
Jonas M Denmark

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

5

With concatenating, we actually create a new data set …

Example: Merging Data Sets

Two data sets are merged to create a new data set.

6

EmpsAU
First Gender EmpID
Togar M 121150
Kylie F 121151
Birin M 121152
PhoneH
EmpID Phone
121150 +61(2)5555-1793
121151 +61(2)5555-1849
121152 +61(2)5555-1665

EmpsAUH
First Gender EmpID Phone
Togar M 121150 +61(2)5555-1793
Kylie F 121151 +61(2)5555-1849
Birin M 121152 +61(2)5555-1665

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

6

In this example of merging, we are matching observations by EmpID and bringing the observations together …

The APPEND Procedure

The APPEND procedure adds the observations from one SAS data set to the end of another SAS data set.

General form of the APPEND procedure:

BASE= names the data set to which observations are added.

DATA= names the data set containing observations that are added to the base data set.

7

PROC APPEND BASE = SAS-data-set

DATA = SAS-data-set;

RUN;

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

7

Like-Structured Data Sets

The data sets contain the same variables.

8

Emps
First Gender HireYear
Stacey F 2006
Gloria F 2007
James M 2007
Emps2008
First Gender HireYear
Brett M 2008
Renee F 2008

proc append base=Emps

data=Emps2008;

run;

p110d01

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

8

Like-Structured Data Sets

9

84 proc append base=Emps

85 data=Emps2008;

86 run;

NOTE: Appending WORK.EMPS2008 to WORK.EMPS.

NOTE: There were 2 observations read from the data set

WORK.EMPS2008.

NOTE: 2 observations added.

NOTE: The data set WORK.EMPS has 5 observations and 3 variables.

Emps
First Gender HireYear
Stacey F 2006
Gloria F 2007
James M 2007
Brett M 2008
Renee F 2008

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

9

Unlike-Structured Data Sets

The BASE= data set has a variable that is not in the DATA= data set.

10

Emps
First Gender HireYear
Stacey F 2006
Gloria F 2007
James M 2007
Brett M 2008
Renee F 2008
Emps2009
First HireYear
Sara 2009
Dennis 2009

proc append base=Emps

data=Emps2009;

run;

p110d01

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

10

Unlike-Structured Data Sets

Emps
First Gender HireYear
Stacey F 2006
Gloria F 2007
James M 2007
Brett M 2008
Renee F 2008
Sara 2009
Dennis 2009

11

90 proc append base=Emps

91 data=Emps2009;

92 run;

NOTE: Appending WORK.EMPS2009 to WORK.EMPS.

WARNING: Variable Gender was not found on DATA file.

NOTE: There were 2 observations read from the data set

WORK.EMPS2009.

NOTE: 2 observations added.

NOTE: The data set WORK.EMPS has 7 observations and 3 variables.

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

11

The SET Statement

The SET statement in a DATA step reads observations from one or more SAS data sets.

Any number of data sets can be in the SET statement.

The observations from the first data set in the SET statement appear first in the new data set. The observations from the second data set follow those from the first data set, and so on.

12

DATA SAS-data-set; SET SAS-data-set1 SAS-data-set2 . . .;

<additional SAS statements> RUN;

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

12

In order to concatenate, we will be using the DATA step with the SET statement which we already know. The difference is there will be multiple data sets on the SET…

Concatenation

Concatenate EmpsDK and EmpsFR to create a new data set named EmpsAll1.

The data sets contain the same variables.

13

EmpsFR
First Gender Country
Pierre M France
Sophie F France
EmpsDK
First Gender Country
Lars M Denmark
Kari F Denmark
Jonas M Denmark

p110d02

data EmpsAll1;

set EmpsDK EmpsFR;

run;

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

13

The RENAME= Data Set Option

The RENAME= data set option changes the name of a variable.

General form of the RENAME= data set option:

The RENAME= option must be specified in parentheses immediately after the appropriate SAS data set name.

If the RENAME= option is associated with an input data set in the SET statement, the action applies to the data set that is being read.

14

SAS-data-set (RENAME = (old-name-1 = new-name-1

old-name-2 = new-name-2

...

old-name-n = new-name-n))

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

14

The RENAME= Data Set Option

SET statement examples:

15

set EmpsCN(rename=(Country=Region))

EmpsJP;

set EmpsCN(rename=(First=Fname

Country=Region))

EmpsJP(rename=(First=Fname));

set EmpsCN

EmpsJP(rename=(Region=Country));

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

15

Interleaving

Interleaving intersperses observations from two or more data sets, based on one or more common variables.

The SET statement with a BY statement in a DATA step interleaves SAS data sets.

Use the SORT procedure to sort the data sets by the BY variable.

16

DATA SAS-data-set; SET SAS-data-set1 SAS-data-set2 . . .; BY <DESCENDING> by-variable(s);

<additional SAS statements> RUN;

The data sets must be sorted by the BY variable.

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

16

Mention the self-study section on interleaving to students. Level 3 exercise is about interleaving.

Match-Merging

Match-merging combines observations from two or more SAS data sets into a single observation in a new data set based on the values of one or more common variables.

17

A B C
1
2
3
C D E
1
2
3

C D E
1
1
2
A B C
1
2
2

C D E
2
3
4
A B C
1
2
4

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

17

In these merging sections, we will look at match-merging …

Match-Merging

18

A B C
1
2
3
C D E
1
2
3
C D E
1
1
2
A B C
1
2
2

One-to-One

A single observation in one data set is related to one and only one observation from another data set based on the values of one or more selected variables.

One-to-Many or Many-to-One

A single observation in one data set is related to more than one observation from another data set based on the values of one or more selected variables and vice versa.

Nonmatches

At least one single observation in one data set is unrelated to any observation from another data set based on the values of one or more selected variables.

C D E
2
3
4
A B C
1
2
4

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

18

There are different types of match-merging, here are three different types …

In this section, we are looking at one-to-one.

Match-Merging

In order to perform match-merging, the observations in each data set must be sorted by the one or more common variables that are being matched.

General form of the SORT procedure:

The SORT procedure orders SAS data set observations by the values of one or more variables.

19

PROC SORT DATA=input-SAS-data-set

<OUT=output-SAS-data-set>;

BY <DESCENDING> by-variable(s);

RUN;

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

19

This is the student’s first introduction to PROC SORT.

The SORT Procedure

The SORT procedure

rearranges the observations in a SAS data set

either replaces the original data set or creates a new data set

can sort on multiple variables

can sort in ascending (default) or descending order

does not generate printed output.

20

PROC SORT DATA=input-SAS-data-set

<OUT=output-SAS-data-set>;

BY <DESCENDING> by-variable(s);

RUN;

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

20

The BY Statement

The BY statement specifies the sorting variables.

PROC SORT first arranges the data set by the values in ascending order, by default, of the first BY variable.

PROC SORT then arranges any observations that have the same value of the first BY variable by the values of the second BY variable in ascending order.

This sorting continues for every specified BY variable.

The DESCENDING option reverses the sort order for the variable that immediately follows in the statement so that observations are sorted from the largest value to the smallest value.

21

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

21

One-to-One Merge

Merge EmpsAU and PhoneH by EmpID to create a new data set named EmpsAUH.

The data sets are sorted by EmpID.

22

data EmpsAUH;

merge EmpsAU PhoneH;

by EmpID;

run;

p110d05

EmpsAU
First Gender EmpID
Togar M 121150
Kylie F 121151
Birin M 121152
PhoneH
EmpID Phone
121150 +61(2)5555-1793
121151 +61(2)5555-1849
121152 +61(2)5555-1665

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

22

Instructors, this one-to-one is so basic we opted not to show compile and execute phases. We will show this in the one-to-may example.

Final Results

23

EmpsAUH
First Gender EmpID Phone
Togar M 121150 +61(2)5555-1793
Kylie F 121151 +61(2)5555-1849
Birin M 121152 +61(2)5555-1665

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

23

One-to-Many Merge

Merge EmpsAU and PhoneHW by EmpID to create a new data set named EmpsAUHW.

The data sets are sorted by EmpID.

24

PhoneHW
EmpID Type Phone
121150 Home +61(2)5555-1793
121150 Work +61(2)5555-1794
121151 Home +61(2)5555-1849
121151 Work +61(2)5555-1850
121152 Home +61(2)5555-1665
121152 Work +61(2)5555-1666

data EmpsAUHW;

merge EmpsAU PhoneHW;

by EmpID;

run;

p110d06

EmpsAU
First Gender EmpID
Togar M 121150
Kylie F 121151
Birin M 121152

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

24

Final Results

25

EmpsAUHW
First Gender EmpID Type Phone
Togar M 121150 Home +61(2)5555-1793
Togar M 121150 Work +61(2)5555-1794
Kylie F 121151 Home +61(2)5555-1849
Kylie F 121151 Work +61(2)5555-1850
Birin M 121152 Home +61(2)5555-1665
Birin M 121152 Work +61(2)5555-1666

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

25

Nonmatches Merge

Merge EmpsAU and PhoneC by EmpID to create a new data set named EmpsAUC.

The data sets are sorted by EmpID.

26

data EmpsAUC;

merge EmpsAU PhoneC;

by EmpID;

run;

p110d07

EmpsAU
First Gender EmpID
Togar M 121150
Kylie F 121151
Birin M 121152
PhoneC
EmpID Phone
121150 +61(2)5555-1795
121152 +61(2)5555-1667
121153 +61(2)5555-1348

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

26

Final Results

The final results include matches and nonmatches.

Matches are observations that contain data from both input data sets.

Nonmatches are observations that contain data from only one input data set.

27

EmpsAUC
First Gender EmpID Phone
Togar M 121150 +61(2)5555-1795
Kylie F 121151
Birin M 121152 +61(2)5555-1667
121153 +61(2)5555-1348

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

27

By default in SAS, you get matches and non-matches …

Outputting to Multiple Data Sets

The DATA statement can specify multiple output data sets.

28

data EmpsAUC EmpsOnly PhoneOnly;

merge EmpsAU(in=Emps) PhoneC(in=Cell);

by EmpID;

if Emps=1 and Cell=1

then output EmpsAUC;

else if Emps=1 and Cell=0

then output EmpsOnly;

else if Emps=0 and Cell=1

then output PhoneOnly;

run;

p110d07

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

28

Mention the two self-study topics, Outputting to Multiple Data Sets which is a PRG2 topic and Many-to-Many Merges with some SQL code.

Outputting to Multiple Data Sets

An OUTPUT statement can be used in a conditional statement to write the current observation to a specific data set that is listed in the DATA statement.

29

data EmpsAUC EmpsOnly PhoneOnly;

merge EmpsAU(in=Emps) PhoneC(in=Cell);

by EmpID;

if Emps=1 and Cell=1

then output EmpsAUC;

else if Emps=1 and Cell=0

then output EmpsOnly;

else if Emps=0 and Cell=1

then output PhoneOnly;

run;

p110d07

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

29

Statements That Enhance Reports

Many statements are used with most reporting procedures to enhance the report.

30

Some of these statements are global statements.

options nocenter;

ods html file='enhanced.html' style=sasweb;

proc print data=orion.sales label;

var Employee_ID First_Name Last_Name Salary;

title1 'Orion Sales Employees';

title2 'Males Only';

footnote 'Confidential';

label Employee_ID='Sales ID'

First_Name='First Name'

Last_Name='Last Name'

Salary='Annual Salary';

format Salary dollar8.;

where Gender='M';

by Country;

run;

ods html close;

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

30

The statements that were added are common to most reporting procedures. These are the statements we want to talk about regardless of what procedure we are using.

Global Statements

The following are global statements that enhance reports:

OPTIONS

TITLE

FOOTNOTE

ODS

Global statements are specified anywhere in your SAS program and they remain in effect until canceled, changed, or your SAS session ends.

31

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

31

To start off with, lets look at the statements that are considered global …

In this section, we will look at OPTIONS, TITLE, and FOOTNOTE. We will look at ODS at the end of this chapter.

The OPTIONS Statement

The OPTIONS statement changes the value of one or more SAS system options.

General form of the OPTIONS statement:

Some SAS system options change the appearance of a report.

The OPTIONS statement is not usually included in a PROC or DATA step.

32

OPTIONS option(s);

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

32

SAS System Options for Reporting

Selected SAS System Options:

33

DATE (default) displays the date and time that the SAS session began at the top of each page of SAS output.
NODATE does not display the date and time that the SAS session began at the top of each page of SAS output.
NUMBER (default) prints page numbers on the first line of each page of SAS output.
NONUMBER does not print page numbers on the first line of each page of SAS output.
PAGENO=n defines a beginning page number (n) for the next page of SAS output.

continued...

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

33

SAS System Options for Reporting

Selected SAS System Options:

34

CENTER (default) centers SAS output.
NOCENTER left-aligns SAS output.
PAGESIZE=n PS=n defines the number of lines (n) that can be printed per page of SAS output.
LINESIZE=width LS=width defines the line size (width) for the SAS log and SAS output.

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

34

SAS System Options for Reporting

35

p112d02

options ls=80 date number;

proc means data=orion.sales;

var Salary;

run;

09:11 Monday, January 14, 2008 35

The MEANS Procedure

Analysis Variable : Salary

N Mean Std Dev Minimum Maximum

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

165 31160.12 20082.67 22710.00 243190.00

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

80 characters wide

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

35

SAS System Options for Reporting

36

1

The FREQ Procedure

Cumulative Cumulative

Country Frequency Percent Frequency Percent

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

AU 63 38.18 63 38.18

US 102 61.82 165 100.00

p112d02

80 characters wide

options nodate pageno=1;

proc freq data=orion.sales;

tables Country;

run;

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

36

The TITLE Statement

The TITLE statement specifies title lines for SAS output.

General form of the TITLE statement:

Titles appear at the top of the page.

The default title is The SAS System.

The value of n can be from 1 to 10.

An unnumbered TITLE is equivalent to TITLE1.

Titles remain in effect until they are changed, canceled, or you end your SAS session.

37

TITLEn 'text ';

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

37

The FOOTNOTE Statement

The FOOTNOTE statement specifies footnote lines for SAS output.

General form of the FOOTNOTE statement:

Footnotes appear at the bottom of the page.

No footnote is printed unless one is specified.

The value of n can be from 1 to 10.

An unnumbered FOOTNOTE is equivalent to FOOTNOTE1.

Footnotes remain in effect until they are changed, canceled, or you end your SAS session.

38

FOOTNOTEn 'text ';

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

38

The TITLE and FOOTNOTE Statements

39

footnote1 'By Human Resource Department';

footnote3 'Confidential';

proc means data=orion.sales;

var Salary;

title 'Orion Star Sales Employees';

run;

p112d03

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

39

The TITLE and FOOTNOTE Statements

40

Orion Star Sales Employees

The MEANS Procedure

Analysis Variable : Salary

N Mean Std Dev Minimum Maximum

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

165 31160.12 20082.67 22710.00 243190.00

ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ

By Human Resource Department

Confidential

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

40

Canceling All Titles and Footnotes

The null TITLE statement cancels all titles.

The null FOOTNOTE statement cancels all footnotes.

41

title;

footnote;

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

41

Assigning Temporary Labels

Instead of the LABEL option in PROC PRINT, the SPLIT= option can be used.

The SPLIT= option specifies the split character, which controls line breaks in column headers.

General form of the SPLIT= option:

42

SPLIT='split-character'

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

42

Assigning Temporary Labels

The SPLIT= option makes PROC PRINT use labels.

Partial PROC PRINT Output

43

Job Annual

Obs Sales ID Title Salary

1 120102 Sales Manager 108255

2 120103 Sales Manager 87975

3 120121 Sales Rep. II 26600

4 120122 Sales Rep. II 27475

5 120123 Sales Rep. I 26190

p112d05

proc print data=orion.sales split='*';

var Employee_ID Job_Title Salary;

label Employee_ID='Sales ID'

Job_Title='Job*Title'

Salary='Annual*Salary';

run;

‹#›

Copyright © 2012, SAS Institute Inc. All rights reserved.

43

References

SAS Programming 1: Essentials- SAS Institute.

SAS: The Power to Know- Official documentation.

www.derby.ac.uk/engtech

www.derby.ac.uk/engtech

Data managment weeks/week 7/Adding additional statistics tutorials.docx

Exercisesc:\Program Files\PowerServ\CourseGraphics\exer_arrow.jpg

Level 1

1. Using BY Groups and Percent Calculations

a. Retrieve the program r102e07 and change the starter program to use BY-group processing to produce this report with a logical page for each value of Customer_Country in the subset.

Desired Results

b. Use a page dimension for Customer_Country to produce this report with three logical pages, one for each value of Customer_Country in the subset and a third logical page for the ALL class variable in the page dimension.

Page Dimension Output for Germany and United States

Table for ALL

Level 2

2. Using SUM and PCTSUM Statistics

a. Retrieve program r102e08 and modify the starter program to produce a report table with the following characteristics.

1) Nest Customer_Age_Group within Customer_Gender in the row dimension. All the statistics in the table are based on the Total_Retail_Price variable.

2) Use ALL to get a summary row for each unique value of Customer_Gender. Label this summary row with the string Gender Summary.

3) Nest Order_Type with SUM and PCTSUM in the column dimension.

4) Use ALL to get a summary column on the right that shows the SUM and PCTSUM for all values of Order_Type. Label this summary column with the string Combined Sales.

5) Suppress the automatic statistic labels for SUM and PCTSUM.

6) Use ALL to produce a final summary row for the report. Label this summary row with the string Total Sales.

7) Use the PICTURE format for percent (PCT.) for the percentages calculated by the PCTSUM statistic.

Desired Results

Hint: To approach this solution, you might think of working from the picture and building a TABLE statement that uses all the default headers, formats and labels. Then, once you have the right table structure, refine your program with formats and labels.

Level 3

3. More About BY-Group Processing

The purpose of this Level 3 exercise is to have you discover how PROC TABULATE output can be impacted with BY-group processing.

a. What two BY statement options can be used to alter the results of the output produced with PROC TABULATE?

Hint: Look in the documentation for a list of statements available to PROC TABULATE.

Data managment weeks/week 7/Invited Talk_PMenu.pptx

Business Analytics with SAS®

PROC PMENU

Suntish T. Narain
MSc Big Data Analytics
06th March 2018

Hello everyone

My name is Suntish and I am from the Big Data Analytics programme

I am here today to walk you through the steps of creating menus, windows and frames

Contents

An overview of Proc PMENU

Proc PMENU syntax and templates

Associating a menu to a window

Creating a dialog box

Introduction to Frames in SAS®

Overview of the Build Environment

Associating Controls and Models to Frames

Associating a menu to a frame

In this presentation, I will introduce you to PMENU procedure, what it is and how we can use it in the SAS application

We will look at creating a menu and the steps involved

We will then look at building a dialog box with radio buttons, checkboxes and text input

The second part of the presentation will be based on frames, how to create them and the build environment

We will look at the components that you can use to create a frame

Finally we will associate a menu to a frame

PROC PMENU - An Overview

The first part is an introduction to PMENU, what it is and how we can use it to define menus

PROC PMENU - Overview

What is the PMENU procedure in SAS?

Menus that can be used in DATA step windows

Any SAS app that enables you to specify customized menus

Why is it important?

Menus can replace command line to execute commands

How does it work?

Activate menu for it to appear

Menus list items that you can select

The PMENU procedure defines menus that can be used in DATA step windows or in any SAS application that enables you to specify customized menus.

Menus can replace the command line as a way to execute commands.

PMENU commands are issued from any command line to activate menus.

When menus are activated, each active window has a menu bar, which lists items that you can select.

The PMENU procedure produces no immediately visible output. It simply builds a catalog of entry of type PMENU that can be used later in an application.

PROC PMENU – Procedure Execution

Multiple menus can de defined by separating their definitions with RUN statements

A group of statements that ends with a RUN statement is called a RUN group

You must completely define a PMENU catalog entry before submitting a RUN statement

Include an initial MENU statement that defines the menu bar

All ITEM statements and any SELECTION, MENU, SUBMENU or DIALOG statements should be within the same RUN group

libname proclib 'U:\My SAS Files\MENU';

proc pmenu catalog=proclib.mycat;

menu menu1;

item end;

item bye;

run;

menu menu2;

item end;

item pgm;

item log;

item output;

run;

menu menu3;

item end;

item pgm;

item log;

item output;

run;

Each menu should be within the RUN statement

The following statements define two separate PMENU catalog entries.

Both are stored in the same catalog, but each PMENU catalog entry is independent of the other.

PROC PMENU – Templates

Create a menu bar with an item that produces a menu

Create a menu bar with an item that opens a dialog box, which displays information and requests text input

PROC PMENU – Templates

Create a menu bar with an item that opens a dialog box, which permits one choice from a list of possible values

Create a menu bar with an item that opens a dialog box, which permits several independent choices

Associating a menu to a window (1)

Point the library to an appropriate location

libname <library_name> ‘<sas_library_location>’;

Create the catalog to store the menu definitions

proc pmenu catalog=<library_name>.<catalog_name>;

The MENU statement specifies select as the name of the catalog entry

The item statements specify the items for the menu bar

Assign a menu to the window

window <window_name> menu=<library_name>.<catalog_name>.<menu_name>

As with any SAS application that you create, a library needs to be specified – creating a menu is no different.

The second statement specifies the catalog in which you want to store the PMENU entries

It invokes the PMENU procedure and specifies where to store all PMENU catalog entries that are created in the PROC PMENU step.

The window statement creates a window. The menu statement associates a menu from the catalog entry to the window.

Associating a menu to a window (2)

1

2

3

menu sa;

item 'BRFSS_Population' dialog=size_sa;

dialog size_sa 'where @1';

text #1 @1 'Enter sample size: ';

text #2 @3 'Sample size <400k';

text #2 @25 len=7;

proc pmenu catalog=proclib.menusun;

menu suntish;

item 'File' menu=f;

item 'Visualisations' menu=v;

item 'Statistics' menu =s;

item 'Sample Selection' menu = sa;

item 'Print Report' menu=print;

item 'Copyright' menu=copyright;

data _null_;

window BRFSS_Suntish menu=proclib.menusun.suntish

#4 @10 ' Business Analytics with SAS '

#5 @10 '---------------------------------'

#6 @10 ' Suntish T. Narain '

#7 @10 ' MSc Big Data Analytics '

#8 @10 '---------------------------------'

#10 @10 ' Example of a SAS application '

#12 @10 'This SAS application will create '

#13 @10 'a menu & associate it to a window'

#14 @10 '---------------------------------‘

#16 @10 '-------- 06th March 2018 --------';

display BRFSS_Suntish;

run;

In section 1:

Declare a library. In this case, PROCLIB is used to store menu definitions.

Second, a catalog is specified for storing menu definitions. Menu definitions will be stored in the PROCLIB.MENUSUN catalog.

Then, a catalog entry is defined. In this case it’s Suntish. The menu statement specifies Suntish as the name of the catalog entry.

Now, we start designing the menu bar. The item statements specify the items for the menu bar.

In Section 2

We start to design the ‘Sample Selection’ menu

A dialog box is created and various text are placed to enable data entry from the user

In Section 3

The window statement defines the primary window of an application

The menu= option associates the catalog entry with this window

The display statement shows the BRFSS_Suntish window

Dialog Box – A MENU Option

WBUILD is a SAS macro. The field numbers %1, %2, and %3 equate to the values that the user specifies with the radio buttons. The field number @1 equates to the search value that the user enters. The field number &1 to &4 equates to the selection the user makes for the checkboxes.

Radiobox statement

Must be used after a DIALOG statement. Must be followed by one or more RBUTTON statements.

Text statement

This is a text string that appears inside the dialog box at the location defined by line and column

Checkbox statement

The checkbox statement requires a column and a line in order to place it in the dialog box. The text describes the check box. The option <ON> is used only if you want the checkbox to be selected at runtime.

Each CHECKBOX statement defines a single item that the user can select independent of other selections.

FRAME - Creating a SAS® Application

Introduction to Frames

What is a frame in SAS®?

Window that contains the fields and buttons that make up the application

How are frames created?

Application is built visually using drag and drop components in the Build Environment

Applications are stored in SAS catalogs

Applications are portable to all SAS software platforms

Building Application - SAS® components

Controls (Checkboxes, Listboxes, Entry fields & Table Viewer)

Models – link data to controls

A frame is defined as the application window that contains the interface, the components of the GUI with which the user interacts

This presentation will guide you through the basic skills that is required to build a simple frame application and associate a menu to it.

In SAS, components are pieces of software that you can use to build an application. Controls and Models are the two types of components that we will look at.

Controls are the visual components of the graphical user interface like checkboxes, radio buttons, Listboxes and table viewer

Models, on the other hand, works behind the scenes to distribute data to controls

We will look at those models in more details as we proceed through this presentation

SAS® Development Environment

The build environment has 4 main windows:

The Build Window (Frame)

This is where the GUI is designed for the application’s look and feel

The Components Window

Repository for controls and models

The Source Window (Source Code)

Text editor for SCL programs

Several source windows opened at the same time

The Properties Window

This is where the characteristics of the components are displayed

Only one properties window can be opened at any one time

Build Window (Frame)

-A frame is where the GUI of the application is built

-Frames are displayed in Build windows

-You can have several frames in one application

The Components Window

This is where the controls and models are located.

The components are dragged and dropped in the Build Window

The Source Window

This is a text editor for creating and editing programming code.

There can be several source windows opened at the same time

This is where SAS Component Language (SCL) programs are added to frames

The Properties Window

- This is where all the properties of all the components on a frame is displayed

- Properties are the defining characteristics of a component

- You can only open one properties window and that window is shared between all open frames

Frame Creation – Associating Control

Execute the below command into the SAS® Command Line to bring up the Build Window

build sasuser.example.Display_data_sun.frame

This is the name of the Frame

When the command is executed, an empty frame appears and the Components window is displayed

From the components window, the user can select items they want in the frame and drag & drop in the Build area.

In this example, a label was used to insert the title of the application window.

3 listboxes have been inserted into the frame.

3 push buttons have been used

Finally, a tableviewer is inserted, which will display the data in table format.

Frame Creation – Associating models

A Library List Model is dragged onto the List Box labelled Select Library (LibrariesListbox)

A Data Set List Model is dragged onto the List Box labelled Select Table (TablesListbox)

A Variable List Model is dragged onto the List Box labelled Select Columns (ColumnsListbox)

A SAS Data Set Model is dragged onto the Table Viewer (Tableviewer1)

Models and controls are designed to work with each other

To provide controls with data, associate them with models

Dropping a model onto a control sets the model attribute on the control

Models and controls are designed to work with each other.

To connect models and controls at build time, simply drag a model onto a control when you are designing the frame, and SAS sets the connection for you. 

To provide all the controls with data, you need to associate them with models.

Dropping a model onto a control sets the model attribute on the control, which is all you need to do to associate a control and a model. 

Frame Creation – Introducing SCL code

SAS Component Language (SCL) controls SAS applications (including controls and frames)

SCL programs are stored in SCL entries, separately from frames.

SCL program or function can be written once and used many times

SCL is an OOP Language, designed to facilitate development of interactive SAS applications

Frame SCL is an SCL entry that is associated with a particular frame

Frame SCL is used to control a frame and the components on that frame

SAS Component Language is the programming language that controls SAS applications (including controls and frames)

SCL is an object-oriented programming language that was designed to facilitate the development of interactive SAS applications

Frame Creation – Frame SCL code

Frame SCL uses reserved sections for program initialization and termination

INIT section executes once before frame is displayed

It is used to initialise variables and open SAS tables

TERM section executes once before the frame is closed

It is used to close the tables and delete variables

Each variable that is used in SCL is of a specific data type (CHAR, NUM and LIST)

All variables should be declared using the DECLARE statement or DCL for short

INIT:

dcl num variable1 rc; /* Declares two numeric variables. */

dcl list myList={}; /* Declares an empty list. */

return;

TERM:

rc=dellist(myList); /* Deletes the list myList. */

return;

Frame SCL uses reserved sections for program initialization and termination 

The INIT section executes once before the frame is displayed to the user

It  is typically used to initialize variables and open SAS tables

The TERM section executes once before the frame is closed

It is typically used to close tables and delete variables that are no longer needed

Frame Creation – Associating SCL code

Variables are instantiated

Init:

Executes before the frame is displayed to the user

LibrariesListBox:

Executes when a selection is made from the LibrariesListbox

TablesListbox:

Executes when a selection is made in the TablesListbox

ColumnsListbox:

Executes when a selection is made in the ColumnsListbox

SubsetButton:

Runs a filter when the button is pressed

ClearButton:

Clears the filter when the button is pressed

term:

Deletes the list when quitting

We first start with the declaration of the variables

SCL code is added to the frame to make it fully functional.

The Source code window is the window in which SCL programs are written

For this application, the SCL code has the following methods.

Frame Creation – Associating SCL code

Variables are instantiated

Initialising the Frame

Term:

dcl num rc;

dcl char(30) displayTable;

dcl list emptyList={};

Init:

subsetButton.enabled='no';

clearButton.enabled='no';

datasetlist1.levelCount=1;

return;

/*************************************/

/* Procedure is executed before the frame is */ /* created – buttons are also reset and the */

/* table option is also set to display data. */

/*************************************/

/************************************/

/* Numerical variable used as a return code */

/* displayTable variable of type character is */ /* created – An empty list is created */

/************************************/

term:

rc=dellist(emptyList);

return;

/*************************************/

/* used to close tables and delete variables */

/* and lists that are no longer needed */

/*************************************/

Variables are initialised at run time so they can be used later on in the program

Init procedure is executed once before the frame is displayed to the user

At runtime, there is nothing to subset or clear, hence why it disables the subsetButton and clearButton by setting the enabled attribute to ‘no’

It also set how the table is displayed in the TablesListBox.

The TERM section executes once before the frame is closed, and is typically used to close tables and delete variables that are no longer needed. You should always delete lists when they are no longer needed

Frame Creation – Associating SCL code

LibrariesListbox:

LibrariesListbox:

if LibrariesListbox.selectedItem ne ' ' then

do;

datasetList1.library=librariesListbox.selectedItem;

variableList1.dataSet=' ';

sasdataset1.table=' ';

subsetButton.enabled='yes';

end;

return;

/******************************************/

/* The dataset library points to the selected */

/* item - The variable list box remains empty */

/* The subset button is enabled. */

/******************************************/

It sets the data set list model to point to the library selected. Since the data set list model is associated with the TablesListbox, the latter is populated.

The procedure also enables the subsetButton as there is now data to subset

Frame Creation – Associating SCL code

TablesListbox:

TablesListbox:

if TablesListbox.selectedItem ne ' ' then

do;

displayTable=librariesListbox.selectedItem || '.' || TablesListbox.selectedItem;

sasdataset1.table=displayTable;

variableList1.dataSet=displayTable;

SubsetButton.enabled='yes';

end;

return;

/************************************************/

/* Concatenate the selected library and the selected table */

/* and give the result to the sasdataset model, the model */

/* supplying the Table Viewer with data. */

/************************************************/

It sets the data set list model to point to the library selected. Since the data set list model is associated with the TablesListbox, the latter is populated.

The procedure also enables the subsetButton as there is now data to subset

The TablesListbox is executed when a selection is made

It concatenates the selected Library with the selected dataset (table). This information is then relayed to the sasdataset model supplying the table viewer.

The subset button remains enabled

Frame Creation – Associating SCL code

ColumnsListbox:

SubsetButton:

ClearButton:

ColumnsListbox:

if listlen(columnsListbox.selectedItems) gt 0 then

sasdataset1.columnOrder=copylist(ColumnsListbox.selectedItems);

return;

/*************************************/

/* Copy the list of selected columns to the */

/* sasdataset1 model, the model supplying */

/* the Table Viewer with data. */

/*************************************/

SubsetButton:

if sasdataset1.table ne ' ' then

rc = sasdataset1._setWhere(0, 'y');

if rc=0 then ClearButton.enabled ='yes';

return;

/*************************************/

/* Call the WHERE subset window */

/* If a WHERE expression is in effect enable */

/* the 'Clear Subset' button */

/*************************************/

ClearButton:

if sasdataset1.table ne ' ' then

sasdataset1._setWhere(emptyList);

ClearButton.enabled ='no';

return;

/********************************/

/* Clear the WHERE expression. */

/* Disable the 'Clear Subset' button. */

/********************************/

This is executed when the selection is made from the ColumnsListbox

The SubsetButton is executed when it is pressed. It calls the subset window – if an expression can be built using the where statement, the Clear Subset button is enabled.

The ClearButton clears the WHERE expression and disables the button – this is because there is no WHERE expression to be cleared anymore

Frame Creation– Testing the Frame

First, a Library is selected

Then a dataset is selected

The data is displayed in the table

and the variables are listed in the columns list

1st

2nd

3rd

4th

When the Application is tested, the user is now enabled to select any of the active libraries in the list.

When you select SAShelp, as in this example, the list under table gets populated.

For example, if Class is selected, both the table and the variable list get populated.

Frame Creation – Testing the Frame

When the user press on the Subset button, a window appears prompting the user to select which subset of data they would like to see.

As you select the attributes, it is listed in the Where section. In this example, Students where Gender is ‘F’ is selected. The results is displayed in the table.

To close the window, the close window is pressed. This ends the program.

FRAME – Associating a MENU

Associating a menu to a Frame - PMENU

Run the command “sasuser.example.Display_data_brfss.frame” to bring up the Frame Build window

Open the Properties of the Frame

In SAS, run the command to bring up the frame in the Build window

Now, In the Build environment, open up the Properties window

Associating a menu to a Frame - PMENU

Ensure that the Properties of the Frame is displayed

Locate the pmenuEntry under the Attribute Name column in the properties window

In the value column, click on the ellipsis… to navigate to the menu

Associating a menu to a Frame - PMENU

Select the Library ‘Proclib’ and then the catalog ‘Menusun’

Select the pmenu catalog entry in the list on the right hand side – ‘Suntish’ is selected. Click OK.

In the Build environment, open up the Properties window

In the value section of the pmenuEntry attribute name, select the ellipsis

Browse through the library and select the menu from the catalog

Test the Frame and the menu will appear

Associating a menu to a Frame - PMENU

On the Build Window, now select Build -> Test to launch the application

On the menu bar, the new sample menu should appear.

In the Build environment, open up the Properties window

In the value section of the pmenuEntry attribute name, select the ellipsis

Browse through the library and select the menu from the catalog

Test the Frame and the menu will appear

Review

Introduced to PROC PMENU

Associated a menu to a window

Created a Dialogbox

Incorporated rbutton, checkboxes and text fields

Introduced to Frames

Component, properties, source windows

Built a demo frame

Buttons, Listbox, table viewer and labels

Added the SAS Component Language (SCL) code

Compiled and Tested the Application

Associated a menu to a frame

Data managment weeks/week 7/Missing Formatted Values tutorials.docx

Level 1

1. Working with Missing Formatted Values

a. The PROC FORMAT step in program r103e01 defines four categories of sales possible for the Order_Type variable. The Orion.Customer_Orders data set only contains Order_Type=2 and Order_Type=3.

b. Retrieve the starter program r103e01 and modify the PROC TABULATE step with the statements or options necessary to produce the desired results.

Starter Program r103e01

proc format;

value alt_ord 1='Retail Sale'

2='Catalog Sale'

3='Internet Sale'

4='Promotional Sale';

run;

proc sort data=orion.customer_orders out=work.orders;

where year(order_date) in (2005, 2006, 2007);

by order_type order_date;

run;

options missing=0;

ods html file='r103e01_New_Format.html' style=sasweb;

proc tabulate data=orders f=comma8. ;

title 'PrintMiss and PreLoadFmt';

class order_date;

class order_type ;

var quantity;

table order_date,

order_type all,

quantity*(n sum median)

/ box="Printmiss and PreLoadFmt";

label Order_Date = 'Order Year'

Quantity = 'Quantity';

format order_date year4. ;

run;

ods html close;

Partial View of Desired HTML Results

The formatted values for Retail Sale and Promotional Sale appear in the output file, even though there are no Order_Type=1 or Order_Type=4 in this subset of data.

Level 2

2. Working with Missing in the Page Dimension

a. Retrieve and modify starter program r103e02 to produce these results:

1) Show Order_Type (formatted with the ALT_ORD. format) in the page dimension.

2) Use the appropriate options so that Retail Sale and Promotional Sale pages show all zeroes in the data cells.

3) Show Order_Date (formatted with the YEAR4. format) in the row dimension. Include a summary line for all the order dates on a page by using the ALL class variable.

4) Show N, SUM, and MEDIAN statistics in the column dimension, based on the Quantity variable.

Desired Results (Four Logical Pages of Output)

Level 3

3. Researching an Alternative to the PRELOADFMT Technique

This Level 3 exercise enables you to investigate an advanced method to accomplish the same end result as using PRINTMISS and PRELOADFMT.

a. There is an additional method that accomplishes the same result as PRELOADFMT and PRINTMISS for missing CLASS variable data. What is that method?

Data managment weeks/week 7/SAS Frame 9.4 Document.pdf

Getting Started with SAS/AF® 9.4 and Frames

SAS® Documentation

The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2013. Getting Started with SAS/AF® 9.4 and Frames. Cary, NC: SAS Institute Inc.

Getting Started with SAS/AF® 9.4 and Frames

Copyright © 2013, SAS Institute Inc., Cary, NC, USA

All rights reserved. Produced in the United States of America.

For a hard-copy book: No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, or otherwise, without the prior written permission of the publisher, SAS Institute Inc.

For a web download or e-book: Your use of this publication shall be governed by the terms established by the vendor at the time you acquire this publication.

The scanning, uploading, and distribution of this book via the Internet or any other means without the permission of the publisher is illegal and punishable by law. Please purchase only authorized electronic editions and do not participate in or encourage electronic piracy of copyrighted materials. Your support of others' rights is appreciated.

U.S. Government License Rights; Restricted Rights: The Software and its documentation is commercial computer software developed at private expense and is provided with RESTRICTED RIGHTS to the United States Government. Use, duplication or disclosure of the Software by the United States Government is subject to the license terms of this Agreement pursuant to, as applicable, FAR 12.212, DFAR 227.7202-1(a), DFAR 227.7202-3(a) and DFAR 227.7202-4 and, to the extent required under U.S. federal law, the minimum restricted rights as set out in FAR 52.227-19 (DEC 2007). If FAR 52.227-19 is applicable, this provision serves as notice under clause (c) thereof and no other notice is required to be affixed to the Software or documentation. The Government's rights in Software and documentation shall be only those set forth in this Agreement.

SAS Institute Inc., SAS Campus Drive, Cary, North Carolina 27513-2414.

December 2013

SAS provides a complete selection of books and electronic products to help customers use SAS® software to its fullest potential. For more information about our offerings, visit support.sas.com/bookstore or call 1-800-727-3228.

SAS® and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.

Other brand and product names are trademarks of their respective companies.

Contents

PART 1 The SAS/AF Development Environment 1

Chapter 1 • Introduction to SAS/AF Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Purpose of This Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Getting More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Software Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Chapter 2 • The Building Blocks of Frame Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 The SAS/AF Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 A Simple Methodology for Frame Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Using Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Chapter 3 • Adding SCL Programs to Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 SAS Component Language (SCL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 The Fundamentals of Frame SCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Dot Notation and SCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Controlling the Execution of SCL Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Calling Other Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Saving Frame SCL Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Compiling Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Testing Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

PART 2 Creating an Application 21

Chapter 4 • Build a Frame Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Overview of the Frame Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Build the Display_data Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Build the Create_report Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Build the Start_menu Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

PART 3 Appendixes 45

Appendix 1 • Defining Attachments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Understanding Attachments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Define Attachments That Resize the Table Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Test the Table Viewer Attachments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Define Attachments That Move the Close Window Button . . . . . . . . . . . . . . . . . . . . . . 55

Appendix 2 • Deploying Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

Appendix 3 • Defining a Subclass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Subclassing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

Create a Close Window Button Subclass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Overriding Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Add the Close Window Button Class to the Components Window . . . . . . . . . . . . . . . . 64 Test the New Close Window Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

vi Contents

Part 1

The SAS/AF Development Environment

Chapter 1 Introduction to SAS/AF Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Chapter 2 The Building Blocks of Frame Applications . . . . . . . . . . . . . . . . . . . . . . . 5

Chapter 3 Adding SCL Programs to Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

1

2

Chapter 1

Introduction to SAS/AF Software

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Purpose of This Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Getting More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Documentation Available on the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Software Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Mainframe Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Overview SAS/AF software is a set of tools for developing applications. Central to the SAS/AF development environment is the frame. You can think of a frame as an application window that contains the interface (the fields and buttons) of your application. With SAS/AF frame application development, you can build much of your application visually, using drag-and-drop components. And because SAS/AF applications are stored in SAS catalogs, they are portable to all SAS software platforms.

Purpose of This Document This document is an introduction to the SAS/AF development environment. It guides you through the basic skills that you need to build a simple frame application. It also gives you a foundation with which you can transition to the larger reference manuals that fully cover SAS/AF software.

Although this document is intended for new users of SAS/AF, you should be familiar with basic SAS concepts such as libraries, catalogs, and catalog entries. You do not need object-oriented programming experience to benefit from this document, but familiarity with object-oriented concepts will certainly help.

Although specific to SAS/AF in SAS®9, the overall processes that are presented in this document also apply to versions of SAS/AF software starting with SAS 8.1.

3

Getting More Information

Help Help is always available when you are using the SAS/AF development environment. To access help, select Help ð SAS Help and Documentation, navigate to SAS Products and then navigate to SAS/AF.

You can also get help on most windows and dialog boxes inside SAS/AF by pressing the F1 key when the window or dialog box is the active window, or by selecting Help ð Using This Window.

To access Help on a component in the Components window, right-click on the component, and then select Help on Class.

Documentation Available on the Web SAS documentation, available in HTML or PDF, is available on the Web at support.sas.com/documentation/onlinedoc/af/.

The following books offer more information about developing applications using SAS/AF software:

• Guide to SAS/AF Applications Development

• SAS Component Language 9.4: Reference

• SAS/AF 9.4 Procedure Guide

Software Requirements To build the frame applications in this document, you must have SAS/AF software installed, and you must have a monitor that is capable of displaying graphics. To run the frame applications in this document, you must have Base SAS software.

Mainframe Support SAS/AF does not support frame application development on a mainframe. However, you can build a frame application on another platform and then port that application to a mainframe platform (see “Native Controls” on page 6 ).

4 Chapter 1 • Introduction to SAS/AF Software

Chapter 2

The Building Blocks of Frame Applications

Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Controls and Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Native Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

The SAS/AF Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Development Environment Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 The Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 The Components Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 The Properties Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 The Source Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

A Simple Methodology for Frame Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Using Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Components Components are pieces of software that you can use to build applications. SAS/AF provides several components that enable you to build graphical user interfaces and then link those interfaces to data. There are two basic types of components: controls and models.

Controls and Models Controls constitute the graphical user interface, and include interface elements that you have seen in Web forms like Check Boxes, List Boxes, and Entry Fields. There are also controls that are specific to SAS/AF such as the Table Viewer (which displays SAS table data).

Models are another type of component. In contrast to the controls that are displayed to the user in the interface, models work behind the scenes to distribute data to controls. For example, to get a List Box to display a list of SAS libraries, you would attach a Library List model to the List Box.

Controls are sometimes called visual components, and models are sometimes called non- visual components. Controls and models are also generically called objects, especially in the context of object-oriented programming.

5

Native Controls The controls that are supplied by SAS always appear as native controls on a platform, even if you ported your application to that platform. This means that if you wrote an application on Solaris, and then ported it to Windows 7, the application would look exactly like other Windows 7 applications.

However, if you run a graphical user interface application on a character-based display (usually on mainframes), the controls (for example, the entry fields and list boxes) are represented as characters, which means the controls will look different from the examples in this document.

The SAS/AF Development Environment

Development Environment Windows The SAS/AF development environment (also called the build environment) has four main windows:

• the frame (contained in a Build window)

• the Components window

• the programming source code (in a Source window)

• the Properties window

6 Chapter 2 • The Building Blocks of Frame Applications

Display 2.1 Main Windows of the SAS/AF Development Environment

Frame

Components

window

Source

window

Properties

window

The Frame A frame is where you build the graphical user interface to your application. Frames are displayed in Build windows. When you save a frame, it is stored as a Frame entry in a SAS catalog. One application can use several frames, and you can have several frames open at the same time.

Display 2.2 A Simple Frame at Build Time

The SAS/AF Development Environment 7

The Components Window The Components window lists commonly used components (controls and models) that you can drag onto a frame. By default the Components window appears when you open or create a frame. Alternatively, you can select a type of control and then double-click on the frame where you want to place it.

Display 2.3 The Components Window (Abbreviated)

To access Help on a component in the Components window, right-click on the component, and then select Help on Class.

The Properties Window The Properties window displays all of the properties of all the components on a frame (including the frame itself). From the Properties window you can view and edit properties.

Properties are the defining characteristics of a component. Properties are the attributes, methods, events, and event handlers that are defined on a component. Although events and event handlers are important for more complex applications, the example later in this document focuses mainly on attributes and uses only one method.

Attributes define information about a component, such as its name, height, and width. Methods define what a component can do, such as selecting or deselecting all the items in a List Box.

You use the Properties window to manipulate properties at build time, and you use programming code to manipulate properties at run time.

With a frame open, you can open the Properties window by selecting View ð Properties Window. You can also open the Properties window by right-clicking a component and selecting Properties.

You can open only one Properties window, and that window is shared between all open frames. The Properties window can only be opened when a frame is open.

8 Chapter 2 • The Building Blocks of Frame Applications

Display 2.4 The Properties Window

The Source Window Source windows contain a text editor for creating and editing programming code. You can have several Source windows open at the same time. The programming language that is used in SAS/AF is examined in “Adding SCL Programs to Frames” on page 13.

Display 2.5 A Source Window

A Simple Methodology for Frame Development The four main SAS/AF windows structure your work flow. Building a frame application typically consists of the following steps:

1. Create a frame and add components to it.

2. Modify the properties of the components, if necessary.

3. Add programming code, if necessary.

4. Save, compile if necessary, and test the frame.

5. Repeat steps 2 through 4 until your application works as desired.

A Simple Methodology for Frame Development 9

Using Models As previously explained, models access and distribute data to controls which then display that data. A simple example of how models and controls work together is populating a List Box with color choices. This is something you might do to let a user select the colors for a pie chart. You could add by hand to the List Box each of the standard SAS colors: Black, Blue, Brown, Cyan, Gray, Green, Magenta, Orange, Pink, Red, White, Yellow. Or you could associate a Color List model with the List Box, and have the List Box populated for you.

Figure 2.1 A Color List Model Supplying a List Box with Available Colors

Color List Model

Just as people can only communicate through a common language, certain models only work with certain controls. The following table lists the controls and models that SAS/AF software provides, and which controls and models can be used together. Within each row of the table, any control on the left can be used with any model on the right.

Table 2.1 Control and Model Compatibility

Controls Models

Combo Box

Dual Selector

List Box

Radio Box

Spin Box

Catalog Entry List

Catalog List

Color List

Data Set List

External File List

Library List

LIST Entry List

SAS File List

SLIST Entry List

Variable List

Variable Values List

10 Chapter 2 • The Building Blocks of Frame Applications

Controls Models

Form Viewer

Table Viewer

SAS Data Set

SCL List

For models and controls that are designed to work with each other, all you need to do is connect them and they automatically communicate with each other. To connect models and controls at build time, simply drag a model onto a control when you are designing the frame, and SAS/AF sets the connection for you. You can also connect a model and a control manually, by setting the control's model attribute in the Properties window.

The example later in this document uses the following models: Catalog Entry List, Library List, and the Variable Values List.

Using Models 11

12 Chapter 2 • The Building Blocks of Frame Applications

Chapter 3

Adding SCL Programs to Frames

SAS Component Language (SCL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Introduction to SCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Frame SCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 When Frame SCL Is Not Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 When Frame SCL Is Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

The Fundamentals of Frame SCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 The Parts of Frame SCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 SCL Labeled Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 SCL Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 SCL Routines and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Dot Notation and SCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Controlling the Execution of SCL Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Calling Other Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Saving Frame SCL Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Compiling Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Testing Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

SAS Component Language (SCL)

Introduction to SCL SAS Component Language (SCL) is the programming language that controls SAS/AF applications (including frames and the controls on frames).

SCL programs are stored in SCL entries, separately from frames. Because of this separation, SCL entries can be accessed by more than one frame, which means that an SCL program or function can be written once and used many times.

SCL is an object-oriented programming language that was designed to facilitate the development of interactive SAS applications. SCL enables you to perform the following tasks:

• calculate and validate field values that are based on user input

• change the attributes of components on a frame at run time

• execute methods of components on a frame

13

• link to other SAS catalog entries, including other SCL entries and frames

• submit SAS programs

• read from and write to SAS tables, SAS catalog entries, and external files

This document does not cover all of these topics. For complete reference information about SCL, refer to the SAS Component Language: Reference (the complete text of which is in the SAS/AF help).

Frame SCL Frame SCL is an SCL entry that is associated with a particular frame (and is the only type of SCL that is used in the example later in this document). Frame SCL is typically used to control a frame and the components on that frame.

For example, in the following diagram, the SCL code that is marked 'A' is the initialization code for the frame, and executes before the frame is displayed. This code specifies that the model that is associated with the List Box look in the SASHELP library for tables. The code that is marked 'B' is executed when a selection is made from the List Box. When a table is selected, the table is displayed in the Table Viewer.

Display 3.1 Frame SCL Controls a Frame

B

A

You can view and edit the frame SCL for any frame that you have open and active by selecting View ð Frame SCL, or by selecting Frame SCL from the frame's pop-up menu.

Although you can open and edit frame SCL just as you can an SCL program that is not associated with a frame, you should only compile frame SCL from its associated frame (see “Compiling Applications” on page 19 for more information).

14 Chapter 3 • Adding SCL Programs to Frames

When Frame SCL Is Not Required A frame does not require an SCL program. Some components that you can add to a frame are designed to perform tasks without additional SCL code. For example, you can add a Push Button control to a frame and set its commandOnClick attribute to end; (with the semicolon). The result is that when a user clicks the button, the END command executes, closing the frame that the button is on. Instead of compiling a frame that has no SCL code (which will produce an error), just save it.

When Frame SCL Is Required Frame SCL is required if you need to do any of the following:

• link to other SCL entries or frames.

• submit SAS programs.

• modify a component's properties at run time. For example, changing the appearance of a control after a user enters input.

• execute a method on a component.

• validate the selections that a user makes.

The Fundamentals of Frame SCL

The Parts of Frame SCL Typical frame SCL code consists of the following:

• labeled sections

• SCL variable declarations

• routines and functions

SCL Labeled Sections An SCL labeled section is a set of programming statements that execute as a unit. A section in SCL begins with a label and ends with a RETURN statement.

Sections that are labeled with the name of a control on the associated frame execute when the user interacts with that control. For example, if you have a Push Button named exitButton on your frame, and you want to use it to confirm that the user wants to exit the application, you might have a labeled section similar to the following in your frame SCL:

exitButton: dcl list message={'Are you sure you want to exit?'}; response=messagebox(message, '!', 'YN', 'Confirm Exit', 'N', ''); if response='YES' then call execcmd('end;'); message=dellist(message); return;

The Fundamentals of Frame SCL 15

The code in the exitButton section executes when that exitButton is clicked, resulting in a dialog box to confirm the exit.

Display 3.2 The exitButton Confirmation Dialog Box

Section labels do not have to match the casing of the name of the control to which they are associated.

Frame SCL uses reserved sections for program initialization and termination (there is also a main processing section, but that is not covered in this document). The INIT section executes once before the frame is displayed to the user, and is typically used to initialize variables and open SAS tables. The TERM section executes once before the frame is closed, and is typically used to close tables and delete variables that are no longer needed. You should always delete lists when they are no longer needed.

Here are example INIT and TERM sections:

INIT: dcl num variable1 rc; /* Declares two numeric variables. */ dcl list myList={}; /* Declares an empty list. */ return;

TERM: rc=dellist(myList); /* Deletes the list myList. */ return;

SCL Variables Each variable that is used in SCL is of a specific data type. The following SCL data types are used in the example application later in this document:

Character declared with the keyword CHAR

Numeric declared with the keyword NUM

List declared with the keyword LIST

All variables should be declared using a DECLARE statement. DECLARE statements do not have to exist in labeled sections. You can declare several variables with one DECLARE statement. You can also use the abbreviation DCL.

CHAR, NUM, and LIST are reserved keywords that indicate the data type of the variables.

CHAR(n) is a notation that enables you to define the length of a character variable, where 'n' is the length in characters, a value up to 32767. By default, character variables are 200 characters long. Consider the following code:

16 Chapter 3 • Adding SCL Programs to Frames

DECLARE NUM n1 n2, /* Two numeric variables. */ CHAR c1, /* A character variable with length 200. */ CHAR(10) c2, /* A character variable with length 10. */ LIST myList={}; /* An empty SCL list. */

SCL Routines and Functions SCL provides a rich set of routines and functions that, for example, enable you to inspect and manipulate SAS catalogs, SAS tables, and the controls on a frame. For detailed information about these functions, refer to SAS Component Language 9.4: Reference.

SCL also supports nearly all of the functions of the Base SAS language. For details about the Base SAS functions, see the SAS 9.4 Functions and CALL Routines: Reference.

Dot Notation and SCL To improve code readability and to reduce the amount of coding that is necessary, SCL supports dot notation, a syntax for accessing component properties (attributes and methods). Using dot notation also enables the compiler to check your syntax at compile time.

In dot notation, the object (the List Box or Table Viewer) is separated from the property (the attribute or method) by a period, which is called a dot. The syntax follows this format:

object.property;

Dot notation is used to set or query attributes, for example:

/* Setting the text color. */ textEntry1.textColor='green';

/* Querying the text color. */ /* The textEntry1 textColor attribute is */ /* returned to the variable 'color'. */ dcl char(10) color; color = textEntry1.textColor;

Dot notation is also used to call methods. For example, the following code deselects all the items in listbox1:

listbox1._deselectAll();

Sometimes you must provide a method with values. These values are called arguments. For example, the following code selects a row of a Table Viewer using the _selectRow method when a Push Button is clicked. The method requires an argument that specifies the row to select, in this case row 5.

init: /* Set the table to view. */ sasdataset1.table='sashelp.class'; return; pushbutton1: /* Select row 5. */ dcl list row={5}; tableviewer1._selectRow(row);

Dot Notation and SCL 17

if row then row=dellist(row); return;

The frame with the selected row:

Sometimes the arguments that you supply to methods are changed in the process of running the method. The following code determines whether item #3 in listbox1 is selected. If the specified row was selected, the variable selected is set to 1. If the specified row was not selected, the variable selected is set to 0.

dcl num selected, num row = 3; listbox1._isSelected(row, selected);

Controlling the Execution of SCL Programs A great deal of control is possible using simple conditional statements. To control application execution in an SCL program, use an IF/THEN conditional statement and a DO group. For example, the following code uses an IF/THEN conditional statement with a DO group to clear values that are entered on a frame when the clearValuesButton is clicked (but only if the frameProtected variable is set to No):

clearValuesButton: if frameProtected = 'No' then do; textEntryName.text = ”; textEntrySalary.text = .; textEntry.text = ”; end; return; /* ...SCL statements... */ return;

For additional information about controlling application flow (the DO WHILE, DO UNTIL, GO TO, and the SELECT and WHEN statements), see the SAS Component Language: Reference.

18 Chapter 3 • Adding SCL Programs to Frames

Calling Other Frames You can use SCL to access one frame from another frame. In fact, your applications can consist of as many frames as you like. For example, the following SCL statement in the frame SCL for Frame1, runs the frame named Frame2 from the current catalog:

call display('Frame2.frame');

The SCL code for Frame1 transfers control to Frame2 and then waits for Frame2 to close. While Frame2 is open, the controls on Frame1 are not accessible. When Frame2 is closed, control returns to the Frame1 SCL, and continues execution, starting with the first statement following the CALL DISPLAY.

For example, assume that a frame contains a Push Button control named Rates. When a user clicks the Rates button, a frame named loanRates is opened that displays rate tables. The frame SCL for the Rates button would look something like this:

RATES: call display('loanRates.frame'); return;

Saving Frame SCL Programs Saving frames and frame SCL is normally a straightforward process: you simply select File ð Save. However, because of the dependencies between a frame and its frame SCL, you must ensure that the frame properly references its SCL entry.

Normally, except for the SCL entry type extension “.scl”, frame SCL has the same name as the frame with which it is associated. For example, the frame myFrame.frame would by default have frame SCL named myFrame.scl.

If you change the name of a frame that already has associated SCL, you must also remember to change the name of the SCL entry to match the name of the FRAME entry. You must then recompile the frame.

Compiling Applications If you add SCL code to a frame, you must compile the frame before you can run it. Compiling is the process of translating your SCL code into a language that can be executed.

To compile a frame in the build environment, make the frame active, and then select Build ð Compile.

If the frame and SCL code compile successfully, you should see a “Code generated” message in the Log window (and no warnings or errors). For example:

NOTE: Compiling MYFRAME.FRAME (SASUSER.EXAMPLE.MYFRAME.SCL). NOTE: Code generated for MYFRAME.FRAME. Code size=4095.

To view the Log window, select View ð Log.

Compiling Applications 19

But as you know, typing code can occasionally lead to a mistake. For example, assume that while typing in some code, you add an extra 'x' to the SCL section name columnsListbox. When you attempt to compile the frame, the Log window shows that the compiler has issued a warning about a potential error:

NOTE: Compiling MYFRAME.FRAME (SASUSER.EXAMPLE.MYFRAME.SCL). WARNING: [Line 43] Label columnsListboxx is Defined but not referenced NOTE: Code generated for MYFRAME.FRAME. Code size=4095.

Although the code compiles with only a warning (notice the words “Code generated” in the last line of the message), the frame will not function properly. Because of the mistake, the code for the columnsListbox will never be executed because the SCL label (with two x's) does not match the control name (with one x).

In general, if a frame compiles with a warning, you might be able to run it, but it could have run-time errors that make it unusable. You should review and understand the cause of all warnings. When appropriate, the cause of warnings should be fixed.

As discussed above, compiling a frame compiles the frame SCL for that frame. You can also compile frame SCL that was opened from its frame and maintain the frame/SCL association.

If you compile frame SCL independently of its frame, the compiled code is not associated with the frame, and the frame will not call the proper code when a user interacts with a control. Only frames with frame SCL code must be compiled.

Testing Applications SAS/AF software provides a testing mode that is available from within the build environment. To test your frame, make it the active window, and then select Build ð Test.

To test your application outside the build environment (that is, without having the frame open), open a SAS Explorer window, right-click on the frame, and select Run. If the frame has not been previously compiled, you will receive an error. You can compile the frame from the SAS Explorer window by right-clicking on the frame, and then selecting Compile.

The only limitation of the Build ð Test menu command is that it does not process SUBMIT statements in SCL code. If you attempt to test a frame that has a SUBMIT block using Build ð Test, the SUBMIT block will fail at run time. Frame applications that are tested outside the build environment (from the SAS Explorer window) perform with complete functionality.

20 Chapter 3 • Adding SCL Programs to Frames

Part 2

Creating an Application

Chapter 4 Build a Frame Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

21

22

Chapter 4

Build a Frame Application

Overview of the Frame Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

Build the Display_data Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Purpose of the Display_data Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Create the Display_data Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Build the User Interface for the Display_data Frame . . . . . . . . . . . . . . . . . . . . . . . . 25 Move and Resize the Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Align the Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Set the Attribute Values for the Display_data Controls . . . . . . . . . . . . . . . . . . . . . . 26 Set Attribute Values for Multiple Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Attach Models to the Display_data Frame Controls . . . . . . . . . . . . . . . . . . . . . . . . . 29 Add SCL Code to the Display_data Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Compile the Display_data Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

Build the Create_report Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Adding to the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Build the Graphical User Interface for the Create_report Frame . . . . . . . . . . . . . . . 35 Set Attribute Values for the Create_report Controls . . . . . . . . . . . . . . . . . . . . . . . . 36 Attach Models to the Create_report Frame Controls . . . . . . . . . . . . . . . . . . . . . . . . 38 Add SCL Code to the Create_report Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Compile the Create_report Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Test the Create_report Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Build the Start_menu Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Creating a Navigation System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Build the Graphical User Interface for the Start_menu Frame . . . . . . . . . . . . . . . . . 42 Set the Attribute Values for the Start_menu Controls . . . . . . . . . . . . . . . . . . . . . . . 42 Add SCL Code to the Start_menu Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Test the Start_menu Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Test the Entire Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

Overview of the Frame Application In this example you build a data viewing application that consists of three frames, each of which has frame SCL. Two of the frames display data, while the third is the navigation system that ties the frames together.

You build the first two frames individually, and then you compile and test them. When you complete the third and final frame you will compile it, and then test the entire application.

23

Build the Display_data Frame

Purpose of the Display_data Frame The Display_data frame enables users to select and display a SAS table as columnar data. The frame also enables users to subset the displayed data by column, and by using a WHERE expression.

Display 4.1 Finished Display_data Frame

Create the Display_data Frame Create the Display_data frame by entering the following command at the SAS command line:

build sasuser.example.Display_data.frame

The SAS command line is usually in the upper-left corner of the main SAS window.

Display 4.2 SAS Command Line

24 Chapter 4 • Build a Frame Application

The empty frame appears and the Components window is displayed.

Build the User Interface for the Display_data Frame To create the graphical user interface for the frame, drag the following controls from the Components window onto the frame and position them as you see in Display 4.3 on page 25:

• one Text Label Control (this is for the title at the top of the frame)

• three List Box Controls

• one Table Viewer Control

• three Push Button Controls

Alternatively, you can select each type of control and then double-click on the frame where you want to place it.

On some UNIX platforms, you might need to press two buttons on your mouse to activate a drag action (consult your host documentation).

If you run out of room while dropping controls on the frame, make the frame bigger by resizing it the way you would resize any other window. You can make it smaller later, after positioning the controls.

After dragging all the controls to the frame, you should now have a frame that resembles the following:

Display 4.3 Preliminary Display_data Frame

If you accidentally drop one control inside another so that the larger control completely surrounds the smaller, you might not be able to select the smaller control. To access the smaller control, select the larger control and move it out of the way so that you can select and move the smaller control to its proper position.

Build the Display_data Frame 25

Move and Resize the Controls After you place the controls on the frame, position them like the controls in Display 4.1 on page 24 by clicking on a control and then placing the mouse pointer on a portion of the light gray border around the control. When the pointer changes into a hand, you can drag the control to a new position.

At this point, the only control that you need to resize is the Table Viewer. To resize a control, select the control and then place the mouse pointer on the dark handles around the control. When the pointer changes into an arrow, you can resize the control.

Figure 4.1 Mouse Pointers for Moving and Resizing Controls

You can also resize controls with pixel-level accuracy using attributes. Resizing controls using attributes is as simple as entering height and width values. Using attributes to size controls is examined later in this document (see “Set the Attributes That Control the Interface” on page 28).

The remaining controls will be resized using attributes later in this example.

Align the Controls Although you might have aligned the controls by hand already, there are layout tools available that can help you do the job precisely.

To align the left edges of the three List Box controls, select all three controls by either holding the SHIFT key and clicking each List Box, or by using the mouse to draw a box around all three (controls are selected when their borders turn thick and gray). Now select Layout ð Align ð Lefts.

You can drag controls that are selected as a group.

Align the remainder of the components so that your frame resembles Display 4.1 on page 24.

Set the Attribute Values for the Display_data Controls

How to Set Attributes To change the appearance and the behavior of the controls at build time, you must set their attributes by using the Properties window. The procedure for setting attributes at build time is the same for all attributes.

26 Chapter 4 • Build a Frame Application

Set the First Attribute The first attribute to set is the text of the banner at the top of the frame (which currently says Label). To set the Textlabel1 label attribute, follow these steps:

1. Open the Properties window by right-clicking in the frame and selecting Properties. Notice in the Properties window that all the components are listed on the left.

2. Select Textlabel1 on the left side of the Properties window.

The attributes for the Textlabel1 control are listed on the right.

3. Scroll up the list of attributes until you see the label attribute.

4. Click inside the Value column on the label row.

5. Type Sales Data and press ENTER.

Notice in the frame that the Textlabel1 control now displays Sales Data.

Display 4.4 The Properties Window While Setting the Textlabel1 label Attribute

Editing the attributes of the

Textlabel1 component

To set the font of the label, follow these steps:

1. Scroll to the font attribute.

2. Click inside the Value column where it says (list).

3. Click on the ellipsis button.

The Font dialog box appears.

4. Change the font to Arial, Regular, 16.

5. Click OK.

In the frame, resize Textlabel1 to make it display the text correctly.

Set the Control Names Because remembering the generic name for each control might be difficult (Listbox2 does not have much meaning), you should rename the controls. Recall that the names of controls are used as section labels in frame SCL code (which will be added later).

In the Properties window, set the name attribute of each control as follows:

• Listbox1 to LibrariesListbox

Build the Display_data Frame 27

• Listbox2 to TablesListbox

• Listbox3 to ColumnsListbox

• Pushbutton1 to SubsetButton

• Pushbutton2 to ClearButton

• Pushbutton3 to CloseButton

Set the Attributes That Control the Interface To set the text that a user sees in the interface, set the following:

• LibrariesListbox title attribute to Select library:

• TablesListbox title attribute to Select table:

• ColumnsListbox title attribute to Select columns:

• ClearButton label attribute to Clear Subset

On the SubsetButton, set the following to add text and an icon:

• buttonStyle attribute to Icon with Text Under

• icon attribute to 715

• height attribute to 40

• label attribute to Subset with WHERE

Although you might want to set the width of the SubsetButton at this point, wait until the next section.

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

So that users can select more than one item from the ColumnsListbox, set its selectionMode attribute to Multiple Selections.

Set Attribute Values for Multiple Controls Attributes that are common between two or more controls can be set simultaneously, which can save time. To set the width of the three List Boxes and the SubsetButton, select all three list boxes and the SubsetButton. To select multiple controls on a frame, either hold down the SHIFT key while you click each control, or drag the mouse pointer across each control.

When all four of the components are selected, the Properties window displays only the attributes that the components have in common. Set the width of all four components to 107.

28 Chapter 4 • Build a Frame Application

Display 4.5 Displaying Shared Attributes

Editing the

attributes of

several

components

Notice on the frame that all four components have changed widths.

You might need to move or align the controls so that they do not overlap.

Attach Models to the Display_data Frame Controls Notice that the List Boxes all display a generic list of four items. This is because they, and the Table Viewer on the right side of the frame, have no access to data. To provide all the controls with data, you need to associate them with models. Dropping a model onto a control sets the model attribute on the control, which is all you need to do to associate a control and a model.

To associate the correct model with the proper control, drag the indicated model onto the control on the frame:

• a Library List Model onto the List Box labeled Select Library (LibrariesListbox)

• a Data Set List Model onto the List Box labeled Select Table (TablesListbox)

• a Variable List Model onto the List Box labeled Select Columns (ColumnsListbox)

• a SAS Data Set Model onto the Table Viewer (Tableviewer1)

You should now see a list of libraries in the LibrariesListbox. By default the Library List model references the currently defined SAS libraries, even at build time. This is why the first List Box displays the current libraries. The other controls don't display any data because, although they are associated with models, those models have not been told where to look for data. You add SCL code to define those data sources in the next section.

Build the Display_data Frame 29

Display 4.6 Display_data Frame after Attaching Models and Setting Attributes

Add SCL Code to the Display_data Frame To add the SCL code, making the frame fully functional, open the frame SCL for the Display_data frame (right-click anywhere in the frame and select Frame SCL). Insert the following code:

/* This is the frame SCL for the Display_data frame. */ /* */ /* The user selects a library from the LibrariesListbox. */ /* The TablesListbox is then populated. */ /* The user selects a table from the TablesListbox. */ /* The ColumnsListbox and Tableviewer1 are then populated. */

dcl num rc; /* Numerical variable used as a return code. */ dcl char(30) displayTable; /* A character variable. */ dcl list emptyList={}; /* Creates an empty list. */ /* Executes before the frame is displayed to the user. */ Init: /* Disable the SubsetButton and the ClearSubset buttons */ /* by setting the 'enabled' attribute on each. */ /* There is nothing yet to subset or clear. */ subsetButton.enabled='no'; clearButton.enabled='no';

/*Set how the table is displayed in TablesListBox. */ datasetlist1.levelCount=1; return;

/*Executes when a selection is made from the LibrariesListbox. */ LibrariesListbox:

30 Chapter 4 • Build a Frame Application

if LibrariesListbox.selectedItem ne ' ' then do; /* Set the Data Set List model to point to the library selected. */ /* Because the Data Set List model is associated with the */ /* TablesListbox, the TablesListbox is populated. */ datasetList1.library=librariesListbox.selectedItem; variableList1.dataSet=' '; sasdataset1.table=' ';

/* Enable the SubsetButton now that there is data to subset. */ subsetButton.enabled='yes'; end; return;

/* Executes when a selection is made from the TablesListbox. */ TablesListbox: if TablesListbox.selectedItem ne ' ' then do; /* Concatenate the selected library and the selected table */ /* and give the result to the sasdataset model, the model */ /* supplying the Table Viewer with data. */ displayTable=librariesListbox.selectedItem || '.' || TablesListbox.selectedItem; sasdataset1.table=displayTable; variableList1.dataSet=displayTable; SubsetButton.enabled='yes'; end; return;

/* Executes when a selection is made from the ColumnsListbox. */ ColumnsListbox: if listlen(columnsListbox.selectedItems) gt 0 then /* Copy the list of selected columns to the sasdataset1 model, */ /* the model supplying the Table Viewer with data. */ sasdataset1.columnOrder=copylist(ColumnsListbox.selectedItems); return;

/* Executes when the 'Subset with WHERE' button is pressed. */ SubsetButton: if sasdataset1.table ne ' ' then /* Call the WHERE subset window. */ rc = sasdataset1._setWhere(0, 'y');

/* If a WHERE expression is in effect, enable the 'Clear Subset' button. */ if rc=0 then ClearButton.enabled ='yes'; return;

/* Executes when the 'Clear Subset' button is pressed. */ ClearButton: if sasdataset1.table ne ' ' then sasdataset1._setWhere(emptyList); /* Clear the WHERE expression. */ ClearButton.enabled ='no'; /* Disable the 'Clear Subset' button. */ return;

term: /* Delete the list when quitting. */

Build the Display_data Frame 31

rc=dellist(emptyList); return;

Save the code by selecting File ð Save, and then close the frame SCL window.

Because the frame entry was already named Display_data.frame, the SCL entry that is associated with the frame is automatically named Display_data.scl. If you change the name of the frame later, the frame assumes that the frame SCL name was also changed, so you must either change the name of the SCL entry to match the frame, or edit the frame's SCLEntry attribute to reference the original SCL entry.

Compile the Display_data Frame With the graphical user interface and the SCL finished, you can now compile the Display_data frame. To compile the frame, make sure it is the active window, and then select Build ð Compile.

If the frame and frame SCL compiled successfully, you should see in the Log window a message similar to the following:

NOTE: Compiling DISPLAY_DATA.FRAME (SASUSER.EXAMPLE.DISPLAY_DATA.SCL). NOTE: Code generated for DISPLAY_DATA.FRAME. Code size=4095.

To view the Log window, select View ð Log.

You should correct all errors and warnings before testing the frame (see “Compiling Applications” on page 19).

Testing

Test the Display_data Frame To test the Display_data frame, make sure it is the active window, and then select Build ð Test.

After the running frame appears, test it by selecting a library, and then a table. For example, select the Sashelp library and the CLASS table. The table data should appear in the Table Viewer.

32 Chapter 4 • Build a Frame Application

Display 4.7 The Completed Display_data Frame

Test the WHERE Subsetting Test the subset capabilities by clicking the Subset with WHERE button. The WHERE Expression builder appears.

Display 4.8 The WHERE Expression Builder Window

Assuming you're viewing the SASHELP.CLASS table, follow these steps to build a simple WHERE expression to display only the females in the SASHELP.CLASS table:

1. Click Sex in the Available Columns list.

2. From the operators list, select EQ.

3. Click <LOOKUP distinct values> in the Available Columns list.

Build the Display_data Frame 33

4. Select F.

5. Click OK.

The CLASS data is displayed with only the rows that contain SEX='F'.

Display 4.9 Results of WHERE SEX='F' Subset

Clear the WHERE subsetting by clicking the Clear Subset button.

Close the frame by clicking the Close Window button.

Removing the Frame Command Line You might have noticed the command prompt at the top of the frame (Command ===>). By default all frames have a command line where users can type SAS commands. To remove the command line at the top of a frame, set the bannerType attribute on the frame to None. The frame is listed in the Properties window as _FRAME_.

After setting the bannerType attribute, recompile, and then test the frame again. Close all Display_data frames when you are finished testing.

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.

34 Chapter 4 • Build a Frame Application

Display 4.10 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 Display 4.10 on page 35:

• 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:

Build the Create_report Frame 35

Display 4.11 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

36 Chapter 4 • Build a Frame Application

• 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.

Display 4.12 The List Editor

Lastly, enlarge the External File Viewer so that it is sized similarly to Display 4.10 on page 35 .

Build the Create_report Frame 37

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 Display 4.10 on page 35.

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');

38 Chapter 4 • Build a Frame Application

/* 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';

Build the Create_report Frame 39

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 Build ð Compile.

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 View ð Log.

You should correct all warnings and errors.

Test the Create_report Frame Although you tested the previous frame, Display_data, with the Build ð Test 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 Build ð Test is not capable of running SUBMIT blocks. If you try to test the Create_report frame using the Build ð Test 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.

40 Chapter 4 • Build a Frame Application

When the frame is running, test it by selecting a Year, a Quarter, and a Country, and then clicking the Create Report button.

Display 4.13 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.

Build the Start_menu Frame

Creating a Navigation System The final frame to build is the navigation system for the other two frames. When complete, the Start_menu frame enables a user to call either the Display_report frame or the Create_report frame with the click of a button.

Display 4.14 Finished Start_menu Frame

Build the Start_menu Frame 41

Build the Graphical User Interface for the Start_menu Frame Create the Start_menu frame by entering the following command at the SAS command line:

build sasuser.example.Start_menu.frame

Resize the frame so that it is about half the default size.

Drag the following controls to the frame:

• one Text Label Control

• three Push Button Controls

You should now have a frame that looks something like this:

Display 4.15 Preliminary Start_menu Frame

Set the Attribute Values for the Start_menu Controls For the Textlabel1 object, set the following:

• label attribute to Sales Viewer

• font attribute to Arial, Regular, 14

Resize the Textlabel1 control so that the text displays properly.

For Pushbutton1, set the following:

• buttonStyle attribute to Icon with Text Under

• height attribute to 60

• icon attribute to 212

• iconStyle attribute to Large Icons

• label attribute to Display Sales Data

• name attribute to DisplayDataButton

• width attribute to 120

42 Chapter 4 • Build a Frame Application

For Pushbutton2, set the following:

• buttonStyle attribute to Icon with Text Under

• height attribute to 60

• icon attribute to 335

• iconStyle attribute to Large Icons

• label attribute to Create Sales Report

• name attribute to CreateRptButton

• width attribute to 120

For Pushbutton3, set the following:

• label attribute to Exit Application

• name attribute to ExitButton

• width attribute to 100

Lastly, set the bannerType attribute of the frame to None.

Arrange the controls so that they resemble Display 4.14 on page 41.

Add SCL Code to the Start_menu Frame Add the following code to the Start_menu frame SCL. When complete, save the SCL and then close the Frame SCL window.

DisplayDataButton: call display('Display_data.frame'); return; CreateRptButton: call display('Create_report.frame'); return;

ExitButton: /* This code displays a confirmation dialog box */ /* when a user clicks the ExitButton. */

/* Create a list that contains the text of the message. */ dcl list message={'Are you sure you want to exit?', 'Be honest.'};

/*Use the SCL MESSAGEBOX function to display a YES/NO dialog box. */ response=messagebox(message, '!', 'YN', 'Confirm Exit'); if response='YES' then call execcmd('end;');

/*Delete the list 'message'. */ message=dellist(message); return;

Test the Start_menu Frame Test the Start_menu frame by selecting Build ð Test. Ensure that the Display Sales Data and Create Sales Report buttons call the appropriate frame, and that the Exit Application button performs as expected.

Build the Start_menu Frame 43

Test the Entire Application To test the entire application, each frame must be compiled individually. And because the Create_report frame uses a SUBMIT statement, you must test the application from outside the build environment (recall the limitation of the testing environment in “Testing Applications” on page 20).

To test the entire application, follow these steps:

1. Close the Start_menu frame (and any other open frames).

2. Run the Start_menu frame from a SAS Explorer window.

3. Test the functionality of each control on each frame.

If you encounter a frame or control that does not function properly, exit the application, compile the offending frame, and then test, diagnose, and fix the problem separately from the larger application.

44 Chapter 4 • Build a Frame Application

Part 3

Appendixes

Appendix 1 Defining Attachments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

Appendix 2 Deploying Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

Appendix 3 Defining a Subclass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

45

46

Appendix 1

Defining Attachments

Understanding Attachments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Control Representation in Attach Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Attachment Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Attachment Direction and Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Moving Controls That Are Attached . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Deleting and Altering Attachments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 For More Information about Attachments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

Define Attachments That Resize the Table Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . 52

Test the Table Viewer Attachments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

Define Attachments That Move the Close Window Button . . . . . . . . . . . . . . . . . . . 55

Understanding Attachments

Introduction Attachments control the spatial relationships between the graphical user interface elements on a window when the window is resized. For example, with the appropriate attachments defined, you can make a control expand when the user enlarges the window, enabling the user to see more data. With a few simple attachments you can greatly increase the utility of an application.

This appendix is a brief introduction to attachments. It guides you through the process of defining attachments so that when a user enlarges the Display_data frame, the Table Viewer on that frame will also grow larger so that more data is visible.

47

Display A1.1 Default Width of Display_data Frame

Display A1.2 Expanded Display_data Frame with Attachments Defined

Control Representation in Attach Mode When you define attachments, the controls on a frame are represented by wire outlines. Compare the regular, build time TestFrame to the frame while defining attachments.

48 Appendix 1 • Defining Attachments

Display A1.3 TestFrame at Build Time (left) and in Attach Mode (right)

Attachment Points You define attachments between a control and the edge of the frame, or between the edge or center of two controls.

An attachment to the edge of a control causes that edge to move when the other end of the attachment (the anchor) is moved. An attachment to the center of a control causes the entire control to move when the anchor for that attachment is moved. Attachments are represented as arrows in the graphical user interface.

In the following display the top Push Button control is attached from its right edge to the right edge of the frame. The lower Push Button control is attached from its center to the right edge of the frame.

Display A1.4 TestFrame with Edge and Center Attachments

Anchors

Edge

Attachment

Center

Attachment

As you can see in the following display, when the frame is enlarged horizontally at run time, the top Push Button (Button1) expands to the right (the edge attachment), and the bottom Push Button (Button2) moves with the right edge of the frame (the center attachment).

Display A1.5 TestFrame at Run Time Before and After Expansion

Understanding Attachments 49

Attachment Direction and Type When you start defining attachments, the Define Attachment dialog box appears so that you can select the direction and type of attachment.

Display A1.6 The Define Attachment Dialog Box

The direction of the attachment governs which control changes when the anchor of the attachment is moved. The control that the attachment arrow points to responds to the moving of the anchor. Remember that an attachment can be anchored to the edge or center of another control, or to the edge of the frame. The left arrow direction is the default attachment direction, and it is the only direction that is used in the example later in this appendix.

Table A1.1 Attachment Directions

Icon Direction Description

Bidirectional Both controls respond to resizing or moving either control. In effect, both ends of the attachment are anchors.

Single Direction

(Right)

The control that the arrow points to responds to a move of the anchor.

Single Direction

(Left)

The control that the arrow points to responds to a move of the anchor.

The type of attachment defines the distance between the anchor and the arrow either in terms of pixels between the points (an absolute attachment type), or as a percentage of space between the points (a relative attachment type). The absolute attachment type is the default attachment type, and it is the only type of attachment that is used in the example later in this appendix.

Table A1.2 Attachment Types

Icon Type Description

Absolute Maintains a fixed number of pixels between attachment points

50 Appendix 1 • Defining Attachments

Icon Type Description

Relative Maintains a percentage of space between attachment points

Delete Deletes attachments (see “Deleting and Altering Attachments” on page 51)

Moving Controls That Are Attached Before you define any attachments, you should adjust the size of the frame and arrange the controls as you want them to be displayed at run time. Once defined, attachments are honored at build time, and if you move an anchor (on a control or a frame), any attached controls are moved or resized according to the attachments.

However, you can select and move multiple controls at build time while not in attach mode without having attachments honored.

In attach mode you can both move and resize individual controls without attachments being honored. The alignment tools are not available in attach mode.

Deleting and Altering Attachments You cannot alter the direction or type of an attachment after it has been created. To change an attachment you must delete it and then create a new attachment.

To delete an attachment, follow these steps after you are in attach mode:

1. Select the delete type (the attachment direction is unimportant).

2. Click inside the control where the attachment is pointing to the control. Do not click on the attachment line itself—doing so will not delete the attachment.

For More Information about Attachments There are many other ways to control screen geometry using attachments. For more information, see the Guide to SAS/AF Applications Development, available at support.sas.com/documentation/onlinedoc/af/.

Understanding Attachments 51

Define Attachments That Resize the Table Viewer This example assumes you have completed at least the Display_data frame that was presented earlier in this document (see “Build the Display_data Frame” on page 24).

To make the Table Viewer on the Display_data frame expand and contract according to the size of the frame, define two attachments by following these steps:

1. With no control selected, select Layout ð Attach ð Define Attachment.

The frame changes into attach mode, the Define Attachment dialog box appears, and the mouse cursor changes.

Display A1.7 The Display_data Frame in Attach Mode

2. In the Define Attachment dialog box, select the direction and type as indicated (both of these selections are the defaults, so they should already be selected):

3. Attach the bottom edge of the Table Viewer to the bottom edge of the frame by placing the mouse cursor inside the lower edge of the Table Viewer. Then click and drag to the bottom edge of the frame, just above the scroll bar, and then release the mouse button.

52 Appendix 1 • Defining Attachments

Figure A1.1 Creating an Attachment to the Table Viewer

4. Make a second attachment from the right edge of the Table Viewer to the right edge of the frame.

There should now be two attachments that point to the Table Viewer control. If your attachments do not resemble the attachments below, delete the attachments that you created and start over (see “Deleting and Altering Attachments” on page 51).

Display A1.8 The Two Completed Table Viewer Attachments

5. Click OK in the Define Attachment dialog box.

The frame returns to the regular, build-time view.

Define Attachments That Resize the Table Viewer 53

Test the Table Viewer Attachments To test the attachments, save the frame and then test it by selecting Build ð Test.

Resize the run-time frame horizontally and then also vertically.

Display A1.9 Display_data Frame Expanded Horizontally

Display A1.10 Display_data Frame Expanded Vertically (with Overlapping Controls)

54 Appendix 1 • Defining Attachments

Clearly, from the previous image of the Display_data frame, something is needed to prevent the Close Window button from overlapping the Table Viewer. The solution is to define attachments for the Close Window button so that it moves as the frame is resized.

Define Attachments That Move the Close Window Button

To fix the problem of the Table Viewer being overlapped, you must define two attachments that move the Close Window button as the frame size is changed.

Attachments to the center of a control cause that control to move when the attachment anchor is moved. This is in contrast to the Table Viewer attachments, which are defined on the edges of the Table Viewer, and cause it to expand or contract, but remain in the same location on the frame.

To define two attachments on the Close Window button, follow these steps:

1. With no control selected, select Layout ð Attach ð Define Attachment.

2. In the Define Attachment dialog box, select the direction and type as indicated (both of these selections are the defaults, so they should already be selected):

3. Attach the center of the Close Window button to the bottom edge of the frame by placing the mouse pointer in the center of the Close Window button. Then click and drag to the bottom edge of the frame, just above the scroll bar, and then release the mouse button.

Define Attachments That Move the Close Window Button 55

Figure A1.2 Creating an Attachment to the Close Window Button

Note that the attachment arrow points to the center (not the edge) of the Close Window button.

4. Make a second attachment from the center of the Close Window button to the right edge of the frame.

Display A1.11 The Four Completed Attachments

Save and test the frame again. As you enlarge the frame, the Table Viewer should resize and the Close Window button should move.

56 Appendix 1 • Defining Attachments

Appendix 2

Deploying Applications

Introduction After you create an application, you can deploy it in such a way that a user can launch it directly, without first having to launch SAS, find the frame, and run it. You can also configure a SAS/AF application to launch as a kiosk-like application, running in the foreground without menus, a title bar, or any of the SAS display manager windows (Program Editor, Log, or Output). When you exit your application, the SAS session automatically ends.

This appendix guides you through the process of modifying a copy of the SAS configuration file and using the INITCMD system option to create an icon that launches the Start_menu frame from the desktop.

These instructions apply to a standard SAS®9.4 installation on the Windows 7 operating system. Consult your SAS host companion for information about the specifics of your operating system.

Edit a Copy of the SAS CFG File A SAS configuration file contains instructions that are executed each time you start a SAS session. To alter a configuration file so that the Start_menu application is executed, follow these steps:

1. Find the SAS CFG file.

Assuming a standard SAS installation on Windows, the CFG file can be found at C: \Program Files\SASHome\SASFoundation\9.4\sasV9.cfg.

2. Duplicate the CFG file, and name the new version Startmenu.CFG.

3. Open the Startmenu.cfg file and add to the bottom of the file, after all other lines, the following options:

-awscontrol notitle -noawsmenu -initcmd "af c=sasuser.example.Start_menu.frame; toolclose; command close; wstatusln off; wwindowbar off;"

4. Save and close the CFG file.

Note that the list of commands in the INITCMD option is enclosed in quotation marks.

57

The following tables describe the SAS system options and SAS commands that are used in the INITCMD option.

Table A2.1 SAS System Options

Option Description

awscontrol notitle Turns off the system menu, and the minimize and maximize buttons in the main SAS window

noawsmenu Turns off the menu bar in the main SAS window

initcmd Specifies commands to execute during the start of a SAS session, and suppresses the Log, Output, Program Editor, Enhanced Editor, and Explorer windows when executing a SAS/AF application

Table A2.2 SAS Commands

Command Description

af c=sasuser.example.start_menu.frame Executes the SAS/AF Start_menu frame

toolclose Turns off the application toolbar

command close Turns off the command bar

wstatusln off Turns off the status line (normally at the bottom of the SAS window)

wwindowbar off Turns off the window bar (normally at the bottom of the main SAS window)

Now you need to create a shortcut that references the Startmenu.CFG file while launching SAS.

Create a Shortcut to SAS That References Startmenu.CFG To create a Windows shortcut that references the Startmenu.CFG file while starting SAS, follow these steps (changing the paths appropriately for your installation):

1. Find the SAS executable.

Assuming a standard SAS installation on Windows, the SAS executable can be located at C:\Program Files\SASHome\SASFoundation\9.4\sas.exe.

2. Create a new shortcut to the SAS executable, naming it StartMenu.

3. Right-click the StartMenu icon, and then select Properties.

4. Edit the Target of the shortcut to reference Startmenu.CFG by appending the following text to the end of the existing Target:

-config 'C:\Program Files\SASHome\SASFoundation\9.4\Startmenu.CFG'

58 Appendix 2 • Deploying Applications

The complete Target line should look something like this. It is split over two lines here, but your Target should be on one line:

"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -config 'C:\Program Files\SASHome\SASFoundation\9.4\Startmenu.CFG'

5. Click OK.

Test the StartMenu shortcut. The Start_menu frame should launch, and the main SAS window should be full screen, with no title, menus, or toolbars. For more information about other start-up options, refer to your host companion and the Base SAS help.

Launching an Application 59

60 Appendix 2 • Deploying Applications

Appendix 3

Defining a Subclass

Subclassing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

Create a Close Window Button Subclass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

Overriding Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

Add the Close Window Button Class to the Components Window . . . . . . . . . . . . . 64

Test the New Close Window Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

Subclassing Instead of defining the same five attributes every time you need a button to close a frame, you can create a button that has all the attributes that you need already defined. You do this by creating a subclass.

A subclass is derived from another class, called a parent class. The subclass inherits all the attributes and methods of that parent. This means that if you change the value of an attribute or the way a method works on the parent, the same change is propagated to the subclass.

You can also define on the subclass new values for attributes that the subclass inherits. These new values override the values that were inherited from the parent class. For example, if the parent class has a width attribute that is set to 50, you can change that value to 100 on the subclass.

This appendix guides you through the process of creating a subclass of the Push Button class. The new subclass overrides the values for the following attributes:

• commandOnClick

• height

• label

• name

• width

After making the Close Window Button subclass, you can drag and drop it onto a frame and the button will function without any further configuration. Besides eliminating repetitive work, subclassing helps to ensure conformity: you won't be able to make the mistake of labeling one button “Close Window” and another “Exit”.

61

Create a Close Window Button Subclass To create a Close Window Button subclass, follow these steps:

1. Create the new class by entering the following command at the SAS command line:

build sasuser.button.closeWindowButton.class

The Class Editor appears.

2. Replace the provided description, CLOSEWINDOWBUTTON.CLASS, with Close Window Button. This description will be used as the class name in the Components window.

3. For the parent class, enter sashelp.classes.pushbutton_c.class, and press ENTER.

Notice how the properties on the left side of the Class Editor are now available.

Overriding Attributes To customize the class and make it look and behave like the Close Window buttons that are currently on the Display_data and Create_report frames, you must change five attributes. Changing an attribute value on a class at build time to a value other than the

62 Appendix 3 • Defining a Subclass

default is called overriding an attribute. The first attribute to override is the width attribute.

To override the width attribute, follow these steps:

1. Click on the Attributes for the class in the Class Properties list (on the left side of the Class Editor).

2. Scroll to the width attribute (in the list of attributes on the right side of the Class Editor).

3. Override the width attribute by right-clicking on the width attribute row and selecting Override.

An 'O' appears in the State column for the width attribute, indicating that the attribute is overridden.

4. In the Initial Value column for width, enter 85.

The default width of all new Close Window Buttons will be 85 pixels.

Using the same general procedure, override the following four attributes on the Close Window Button class and set them to the indicated value:

• commandOnClick: end;

Note the semicolon at the end of the command.

• height: 30

• label: Close Window

• name: CloseWindowButton

When you are finished, close the Class Editor by clicking Yes in the confirmation dialog box to save your changes.

Overriding Attributes 63

Add the Close Window Button Class to the Components Window

Now that you have a new Close Window Button class, you need to make it accessible at build time so that you can drag it to and drop it onto a frame. To make the new button subclass appear in the Components window, follow these steps:

1. Create a frame or open an existing frame.

The Components window appears.

2. Right-click in the Components window and select Add Classes.

3. Enter sasuser.button.closeWindowButton.class or navigate to the class and select it.

The class appears at the top of the Components window. The class will remain in the Components window, even between SAS sessions, until you remove it.

4. Close the frame without saving it.

You can also drag a class from a SAS Explorer window to a frame. Doing so means that you do not have to add the class to the Components window.

Test the New Close Window Button To test the new Close Window Button, delete the existing Close Window button on the Display_data frame, and then add the new Close Window Button to the frame. Because you set all the attributes on the Close Window Button subclass, the button will work without any additional configuration (although you will have to redefine the attachments to the Close Window Button).

If you want to change something about the Close Window Button, in most cases you only have to make a change to the class, and the change is propagated to all the instances of the Close Window Button in all frames that use it.

A complete discussion of object-oriented development is beyond the scope of this appendix, but creating this simple subclass demonstrates how useful subclassing can be. For more information about object-oriented development in SAS/AF, see the Guide to SAS/AF Applications Development.

64 Appendix 3 • Defining a Subclass

Glossary

active window the window to which keyboard input is directed. Only one window can be active at a time.

argument a value that is provided or returned when calling a method.

attachment a way to control the position, size, and movement of controls on a frame.

attribute a characteristic of a component such as its name, color, size, or the data it references. See also Property.

banner the command prompt in the upper-left corner of a frame. Controlled by the bannerType attribute on the Frame class.

build environment the tools and windows in SAS/AF that are used to construct frame applications.

build time the period when a program is in the process of being built; when it is not executing.

catalog See SAS catalog.

catalog entry See SAS catalog entry.

class a template for an object. A class defines all of an object's characteristics (attributes) and the operations (methods) that the object can perform. See also object.

compile to translate SCL code and frame objects into a form that can be executed.

component a control or a model.

65

control a type of component that is visual in nature; as opposed to a model, which has no visual representation. For example, Check Boxes, List Boxes, and Push Buttons. Controls are also sometimes called visual components. See also model.

dot notation a syntax for accessing the properties of a component. In dot notation, the object is separated from the property by a period, which is called a dot. For example, the following syntax would call the _deselectAll method on the listbox1 object: listbox1._deselectAll( )

frame an area that contains controls; analogous to a window.

frame entry the SAS catalog entry type for a frame.

frame SCL SCL that is associated with a specific frame.

handle a graphic representation on the edge of a frame or a control that designates areas that are used to resize or move the frame or control.

INIT a reserved SCL label that indicates the initialization code of an SCL program.

initialization the first stage of frame execution before a frame is displayed. Typically used to declare and set variables and define data sources.

label See SCL label.

labeled section one or more SCL statements that are identified by an SCL label. See SCL label.

mainframe a high-performance computer made for multi-user, processor-intensive computing. Typically used by businesses and for scientific research.

method an action that is defined for a class. For example, the action of deselecting all items is defined as the _deselectAll method on the List Box class.

model a type of component that provides attributes and methods for querying and modifying data sources. For example, a SAS Data Set model contains methods for reading and manipulating SAS tables.

native control the presentation of a control such that it appears to have been built specifically for a platform. For example, a control built on a UNIX system and then ported to Windows 7 will be indistinguishable from other Windows 7 controls.

66 Glossary

non-visual component another term for a model.

object a specific instantiation of a class. For example, when you drag a List Box control (a class) onto a frame, you create the listbox1 object. The terms object and instance are often used interchangeably.

parent class the class from which another class is derived.

PROC See SAS procedure.

procedure See SAS procedure.

property any of the characteristics of a component that collectively determine the component's appearance and behavior. Both attributes and methods are types of properties.

run time the period when a program is executing.

SAS catalog a SAS file that stores many different kinds of information in smaller units called catalog entries. A single SAS catalog can contain several different types of catalog entries. See also SAS catalog entry.

SAS catalog entry a storage unit within a SAS catalog. Each entry has an entry type that identifies its purpose to SAS.

SAS Component Language (SCL) See SCL (SAS Component Language).

SAS procedure a program that is accessed with a PROC statement. SAS procedures can be used to produce reports, manage files, or analyze data. Many procedures are included with the Base SAS software.

SCL (SAS Component Language) a programming language that is provided with SAS/AF software. You can use SCL to develop interactive applications that manipulate SAS data sets and external files.

SCL label a word that indicates the beginning of a section of SCL code.

subclass a class that is derived from another class. The subclass inherits the attributes and methods of its parent class, and can also possess its own unique attributes and methods. Technically, almost all SAS/AF classes are subclasses because they are derived from other classes.

subclassing the process of deriving a new class from an existing class. See also subclass.

Glossary 67

SUBMIT a command that causes SAS to compile and execute a program.

TERM a reserved SCL label that indicates the code that is run when an SCL program ends.

visual component another term for a control.

WHERE expression one or more criteria for retrieving data.

68 Glossary

  • Contents
  • The SAS/AF Development Environment
    • Introduction to SAS/AF Software
      • Overview
      • Purpose of This Document
      • Getting More Information
        • Help
        • Documentation Available on the Web
      • Software Requirements
        • Mainframe Support
    • The Building Blocks of Frame Applications
      • Components
        • Controls and Models
        • Native Controls
      • The SAS/AF Development Environment
        • Development Environment Windows
        • The Frame
        • The Components Window
        • The Properties Window
        • The Source Window
      • A Simple Methodology for Frame Development
      • Using Models
    • Adding SCL Programs to Frames
      • SAS Component Language (SCL)
        • Introduction to SCL
        • Frame SCL
        • When Frame SCL Is Not Required
        • When Frame SCL Is Required
      • The Fundamentals of Frame SCL
        • The Parts of Frame SCL
        • SCL Labeled Sections
        • SCL Variables
        • SCL Routines and Functions
      • Dot Notation and SCL
      • Controlling the Execution of SCL Programs
      • Calling Other Frames
      • Saving Frame SCL Programs
      • Compiling Applications
      • Testing Applications
  • Creating an Application
    • Build a Frame Application
      • Overview of the Frame Application
      • Build the Display_data Frame
        • Purpose of the Display_data Frame
        • Create the Display_data Frame
        • Build the User Interface for the Display_data Frame
        • Move and Resize the Controls
        • Align the Controls
        • Set the Attribute Values for the Display_data Controls
        • Set Attribute Values for Multiple Controls
        • Attach Models to the Display_data Frame Controls
        • Add SCL Code to the Display_data Frame
        • Compile the Display_data Frame
        • Testing
      • Build the Create_report Frame
        • Adding to the Application
        • Build the Graphical User Interface for the Create_report Frame
        • Set Attribute Values for the Create_report Controls
        • Attach Models to the Create_report Frame Controls
        • Add SCL Code to the Create_report Frame
        • Compile the Create_report Frame
        • Test the Create_report Frame
      • Build the Start_menu Frame
        • Creating a Navigation System
        • Build the Graphical User Interface for the Start_menu Frame
        • Set the Attribute Values for the Start_menu Controls
        • Add SCL Code to the Start_menu Frame
        • Test the Start_menu Frame
        • Test the Entire Application
  • Appendixes
    • Defining Attachments
      • Understanding Attachments
        • Introduction
        • Control Representation in Attach Mode
        • Attachment Points
        • Attachment Direction and Type
        • Moving Controls That Are Attached
        • Deleting and Altering Attachments
        • For More Information about Attachments
      • Define Attachments That Resize the Table Viewer
      • Test the Table Viewer Attachments
      • Define Attachments That Move the Close Window Button
    • Deploying Applications
    • Defining a Subclass
      • Subclassing
      • Create a Close Window Button Subclass
      • Overriding Attributes
      • Add the Close Window Button Class to the Components Window
      • Test the New Close Window Button
  • Glossary

Data managment weeks/week 7/UML Summary.pptx

Data Management and Business Intelligence 5CC519

www.derby.ac.uk/engtech

UML summary

http://www.tutorialspoint.com/uml

Dr John Panneerselvam

College of Engineering and Technology, University of Derby

Sensitivity: Internal

1

www.derby.ac.uk/engtech

UML stands for Unified Modelling Language.

UML is not a programming language like C++, Java, COBOL etc.

UML is a pictorial language used to make software blueprints

UML can be described as a general purpose visual modelling language to visualize, specify, construct and document software system.

Also used to model non software systems, e.g. process flow in a manufacturing unit etc.

UML Introduction

Sensitivity: Internal

2

www.derby.ac.uk/engtech

Define a general purpose modelling language which all modellers can use

Simple to understand and use.

Wide audience: developers, business users, ordinary people with a need to understand a “system”.

The “system” may or may not be software. UML is not a development method, rather an accompaniment process to make a successful system.

A simple modelling mechanism capable of modelling all possible systems.

Goals of UML

Sensitivity: Internal

3

www.derby.ac.uk/engtech

Things

Structural

Behavioural

Grouping

Annotational

Relationship

UML Diagrams

UML Building Blocks

Sensitivity: Internal

4

www.derby.ac.uk/engtech

Things

Structural

Class

Interface

Collaboration

Use case

Active classes

Components

Nodes

Behavioural

Interaction

State machine

Grouping

Package

Annotational

Note

Sensitivity: Internal

5

www.derby.ac.uk/engtech

Dependency

Association

Generalisation

Realisation

Relationship

Sensitivity: Internal

6

www.derby.ac.uk/engtech

Diagrams

Structural Diagrams

1. Class diagram

2. Object diagram

3. Component diagram

4. Deployment diagram

Behavioural Diagrams

5. Use case diagram

6. Sequence diagram

7. Collaboration diagram

8. Statechart diagram

9. Activity diagram

Sensitivity: Internal

7

Diagrams: Structural: Class Diagram

Class diagrams are the most common diagrams used in UML. Class diagram consists of classes, interfaces, associations and collaboration.

Class diagrams basically represent the object oriented view of a system which is static in nature.

Active class is used in a class diagram to represent the concurrency of the system.

Class diagram represents the object orientation of a system. So it is generally used for development purpose. This is the most widely used diagram at the time of system construction.

www.derby.ac.uk/engtech

Sensitivity: Internal

8

Class Notation

Top section used to name the class.

Second section used to show the attributes of the class.

Third section describes the operations performed by the class.

Final section is optional. Used to show any additional components.

www.derby.ac.uk/engtech

Sensitivity: Internal

9

Sample Class Diagram

www.derby.ac.uk/engtech

Sensitivity: Internal

10

Diagrams: Structural: Object Diagram

Object diagrams can be described as an instance of class diagram. So these diagrams are more close to real life scenarios where we implement a system.

Object diagrams are a set of objects and their relationships just like class diagrams and also represent the static view of the system.

The usage of object diagrams is similar to class diagrams but they are used to build prototype of a system from practical perspective.

www.derby.ac.uk/engtech

Sensitivity: Internal

11

Sample Object Diagram

www.derby.ac.uk/engtech

Sensitivity: Internal

12

Diagrams: Structural: Component Diagram

Component diagrams represent a set of components and their relationships. These components consist of classes, interfaces or collaborations.

So Component diagrams represent the implementation view of a system.

During design phase software artefacts (classes, interfaces etc) of a system are arranged in different groups depending upon their relationship. These groups are known as components.

Finally, component diagrams are used to visualise the implementation

www.derby.ac.uk/engtech

Sensitivity: Internal

13

Sample Component Diagram

www.derby.ac.uk/engtech

Sensitivity: Internal

14

Diagrams: Structural: Deployment Diagram

Deployment diagrams are a set of nodes and their relationships. These nodes are physical entities where the components are deployed.

Deployment diagrams are used for visualising deployment view of a system. This is generally used by the deployment team.

www.derby.ac.uk/engtech

Sensitivity: Internal

15

Sample Deployment Diagram

www.derby.ac.uk/engtech

Sensitivity: Internal

16

Diagrams: Behavioural: Use case Diagram

Use case diagrams are a set of use cases, actors and their relationships. They represent the use case view of a system.

A use case represents a particular functionality of a system.

So use case diagram is used to describe the relationships among the functionalities and their internal/external controllers. These controllers are known as actors.

www.derby.ac.uk/engtech

Sensitivity: Internal

17

Sample Use Case Diagram

www.derby.ac.uk/engtech

Sensitivity: Internal

18

Diagrams: Behavioural: Sequence Diagram

A sequence diagram is an interaction diagram. The name indicates that the diagram deals with sequences, which are the sequence of messages flowing from one object to another.

Interaction among the components of a system is very important from implementation and execution perspective.

Sequence diagram is used to visualize the sequence of calls in a system to perform a specific functionality.

www.derby.ac.uk/engtech

Sensitivity: Internal

19

Sample Sequence Diagram

www.derby.ac.uk/engtech

Sensitivity: Internal

20

Diagrams: Behavioural: Collaboration Diagram

Collaboration diagram is another form of interaction diagram. It represents the structural organisation of a system and the messages sent/received. Structural organisation consists of objects and links.

The purpose of collaboration diagram is similar to the sequence diagram, but the specific purpose of collaboration diagram is to visualise the organisation of objects and their interaction.

www.derby.ac.uk/engtech

Sensitivity: Internal

21

Sample Collaboration Diagram

www.derby.ac.uk/engtech

Sensitivity: Internal

22

Diagrams: Behavioural: Statechart Diagram

Any real time system is expected to be influenced by internal/external events. These events are responsible for state change of the system.

Statechart diagram is used to represent the event driven state change of a system. It describes the state change of a class, interface etc.

State chart diagram is used to visualise the reaction of a system by internal/external factors.

www.derby.ac.uk/engtech

Sensitivity: Internal

23

Sample Statechart Diagram

www.derby.ac.uk/engtech

Sensitivity: Internal

24

Diagrams: Behavioural: Activity Diagram

Activity diagram describes the flow of control in a system. So it consists of activities and links. The flow can be sequential, concurrent or branched.

Activities are the functions of a system. Numbers of activity diagrams are prepared to capture the entire flow in a system.

Activity diagrams are used to visualise the flow of controls in a system. This is prepared to have an idea of how the system will work when executed.

www.derby.ac.uk/engtech

Sensitivity: Internal

25

Sample Activity Diagram

www.derby.ac.uk/engtech

Sensitivity: Internal

26

Diagram commonality:

It should be clear that the diagrams have some relationship with one another.

e.g. Component diagrams depend on classes, interfaces etc. which are part of class/object diagram.

e.g. Deployment diagrams are dependent on components used to make component diagrams.

www.derby.ac.uk/engtech

Sensitivity: Internal

27

System logic in SAS

Pre-process (how you prepare your datasets)

Analysis

Post-Process (how you present your results)

www.derby.ac.uk/engtech

Sensitivity: Internal

28

Your MIS in SAS

www.derby.ac.uk/engtech

Sensitivity: Internal

29

www.derby.ac.uk/engtech

Sensitivity: Internal

30

Data managment weeks/week 8/Lecture 8 Distribution Analysis in SAS.ppt



Data Management and Business Intelligence
5CC519

www.derby.ac.uk/engtech



Lecture 5 – Picturing Distributions and Outliers in SAS

Dr John Panneerselvam

College of Engineering and Technology, University of Derby


*

Distributions

*

Descriptive Analytics

The goals when you are describing data are to

  • screen for unusual data values
  • inspect the spread and shape of continuous variables
  • characterize the central tendency
  • draw preliminary conclusions about your data.

*

A Normal Distribution

Can use the skewness and kurtosis along with the histogram to help us decide if your sample follows a normal distribution or not.

*

*

The UNIVARIATE Procedure

General form of the UNIVARIATE procedure:

PROC UNIVARIATE DATA=SAS-data-set <options>;
VAR variables;

CDFPLOT <variables> < / options> ;

HISTOGRAM variables </ options>;

PROBPLOT variables </ options>;

QQPLOT <variables> < / options> ;

VAR variables ;

WEIGHT variable ;

RUN;

*

Descriptive Statistics

  • Mean
  • Sum
  • Sum of the Weights
  • Standard Deviation
  • Variance
  • Covariance
  • Skewness
  • Kurtosis

*

Creating Histogram

title 'Analysis of Plating Thickness';

proc univariate data=Trans noprint;

histogram Thick;

run;

*

Two Way Comparative Histogram

title 'Results of Supplier Training Program';

proc univariate data=Disk noprint;

class Supplier Year;

histogram Width / intertile = 1.0

vaxis = 0 10 20 30

ncols = 2

nrows = 2;

run;

*

Histogram with a Fit

proc univariate data=Robots;

histogram Length /

beta(theta=10 scale=0.5 fill)

href = 10

hreflabel = 'Lower Bound'

odstitle = 'Fitted Beta

Distribution of Offsets';

inset n = 'Sample Size' /

pos=ne cfill=blank;

run;

*

The UNIVARIATE Procedure

*

CDF with a Fit

proc univariate data=Cord noprint;

cdf Strength / normal;

inset normal(mu sigma);

run;

*

Quantile Fit

symbol v=plus;

title 'Two-Parameter Lognormal Q-Q Plot for Diameters';

ods graphics off;

proc univariate data=ModifiedMeasures noprint;

qqplot LogDiameter / normal(mu=est sigma=est)

square

vaxis=axis1;

inset n mean (5.3) std (5.3) / pos = nw header = 'Summary Statistics';

axis1 label=(a=90 r=0);

run;

*

Outliers

*

Box-and-Whisker Plots

The mean is denoted by a ◊.

largest point <= 1.5 I.Q. from the box

the 75th percentile

the 25th percentile

the 50th percentile (median)

smallest point <= 1.5 I.Q. from the box

outliers > 1.5 I.Q. from the box

1.5 I.Q.

*

Made up of percentiles.

Blue box is the interquartile range.

*

The BOXPLOT Procedure

General form of the UNIVARIATE procedure:

PROC BOXPLOT options ;

BY variables ;

INSET keywords </options> ;

INSETGROUP keywords </ options> ;

PLOT analysis-variable*group-variable <(block-variables)> <=symbol-variable> </ options > ;

Run;

*

Creating a Box Plot

proc boxplot data=Turbine;

plot KWatts*Day / boxstyle = schematic

outbox = OilSchematic;

run;

*

Enhancing a Box Plot

title 'Box Plot for Power Output';

proc boxplot data=Turbine;

plot KWatts*Day;

inset min mean max stddev / header = 'Overall Statistics‘ pos = tm;

insetgroup min max /

header = 'Extremes by Day';

run;

*

*

  • Big Data Fundamentals Concepts, Drivers and Techniques (Available in Week 5)
  • SAS Programming 1: Essentials- SAS Institute.
  • SAS: The Power to Know- Official documentation.

www.derby.ac.uk/engtech

References

*

www.derby.ac.uk/engtech

Can use the skewness and kurtosis along with the histogram to help us decide if your sample follows a normal distribution or not.

*

*

Made up of percentiles.

Blue box is the interquartile range.

*

Data managment weeks/week 8/Software testing.pptx

Data Management and Business Intelligence 5CC519

www.derby.ac.uk/engtech

Software Testing

Dr John Panneerselvam

College of Engineering and Technology, University of Derby

Sensitivity: Internal

1

www.derby.ac.uk/engtech

Overview

▪ Definition of Software Testing

▪ Problems with Testing

▪ Benefits of Testing

▪ Effective Methods for Testing

Sensitivity: Internal

2

www.derby.ac.uk/engtech

Definition

Software testing is the process of executing a software system to determine whether it matches its specification and executes in its intended environment.

“Program testing can be a very effective way to show the presence of bugs, but it is hopelessly inadequate for showing their absence” [Dijkstra, 1972]

Sensitivity: Internal

3

www.derby.ac.uk/engtech

Cost of Delaying the Release of a Software

Product

Timing is another important factor to consider.

New products: The first to the market often sells better than superior products that are released later.

Sensitivity: Internal

4

www.derby.ac.uk/engtech

Cutting Testing Costs can Increase other

Costs

Customer support can be very expensive.

Less bugs = less calls.

Customers will look for more reliable solutions.

Software organizations must perform cost benefit analysis’ to determine how much to spend on testing

Sensitivity: Internal

5

www.derby.ac.uk/engtech

Problems with Testing

Since it is impossible to find every fault in

a software system, bugs will be found by

customers after the product is released

Sensitivity: Internal

6

www.derby.ac.uk/engtech

Reasons that Bugs Escape Testing

User executed untested code.

User executed statements in a different order than was tested.

User entered an untested combination of inputs.

User’s operating environment was not tested

Sensitivity: Internal

7

www.derby.ac.uk/engtech

Why Can’t Every Bug be Found

Too many possible paths.

Too many possible inputs.

Too many possible user environments.

Sensitivity: Internal

8

www.derby.ac.uk/engtech

Too Many Possible Paths

Sensitivity: Internal

9

www.derby.ac.uk/engtech

Too Many Possible Inputs

Programs take input in a variety of ways: mouse, keyboard, and other devices.

Must test Valid and Invalid inputs.

Most importantly, there are an infinite amount of sequences of inputs to be tested.

Sensitivity: Internal

10

www.derby.ac.uk/engtech

Too Many Possible User Environments

Difficult to replicate the user’s combination of hardware, peripherals, OS, and applications.

Impossible to replicate a thousand-node network to test networking software.

Sensitivity: Internal

11

www.derby.ac.uk/engtech

Phases of the Software Process

Sensitivity: Internal

12

www.derby.ac.uk/engtech

Why No Testing Phase?

Testing must be done at every phase.

Testing of a phase must be built upon and checked against the results of the previous phase.

Non-execution based testing is done in early phases (before executable code is produced).

Execution and non-execution based testing can be done in later phases.

Sensitivity: Internal

13

www.derby.ac.uk/engtech

Black-Box / White-Box Testing

Black-box tests are driven by the program’s specification

White-box tests are driven by the program’s implementation

Sensitivity: Internal

14

www.derby.ac.uk/engtech

Sensitivity: Internal

15

Data managment weeks/week 9/Creating Detail Reports with the REPORT Procedure.pdf

06/03/2016

1

11

Chapter 4: Creating Detail Reports with the REPORT Procedure

4.1 Using Basic REPORT Procedure Statements

4.2 Adding Summary Lines

4.3 Computing an Additional Column

Portions Copyright © 2001, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. Reproduced

with permission of SAS Institute Inc., Cary NC, USA. SAS Institute Inc. makes no warranties

with respect ot these materials and disclaims all liability therefor

2

Objectives � Understand and use the NOWD option.

� Use the COLUMN statement and DEFINE statement

to create detail reports.

� Use PROC REPORT and DEFINE statement options to alter the report appearance.

� Specify variable usage for detail reports.

2

06/03/2016

2

3

The REPORT Procedure Basics The REPORT procedure is a single report-writing tool that

combines features of these SAS components:

� PRINT procedure: ability to produce detail reports

� MEANS procedure: ability to summarize observations

and calculate summary statistics

� TABULATE procedure: ability to summarize

observations, calculate summary statistics and

produce cross-tabular reports

� DATA step: ability to use language features such as

functions, assignment statements and conditional logic

to modify report items, calculate new report items or perform special processing at report breaks.

3

4

REPORT Procedure Basics The REPORT procedure produces a variety of reports:

� detail reports based on SAS data sets.

– Detail reports have a report row for every

observation in the data set or every observation in a subset of data.

� summary reports based on SAS data sets.

– Summary reports have a report row for a group of observations in the data set or a group of observations in a subset of data.

� detail or summary reports with summary lines

calculated by the procedure. You can request subtotals and grand totals independently of each other.

4

06/03/2016

3

5

Additional REPORT Procedure Features The REPORT procedure also

� computes columns using data set variables or temporary variables

� customizes break lines before or after a group or

report

� produces cross-tabular reports where every column

across the top of the report represents a variable value

� creates reports in noninteractive (or batch) mode

(ODS or LISTING destinations)

� generates reports in interactive mode (REPORT

window only)

� generates report code in interactive mode (REPORT window only) that can be saved, modified and submitted in batch mode.

5

66

06/03/2016

4

7

4.01 Multiple Choice Poll What is the best description of a detail report?

a. A detail report is a report with over 50 variables and

100 rows.

b. A detail report shows numbers with 12 decimal

places.

c. A detail report has a row for every observation in the

data set or subset of data.

d. A detail report contains a row for every observation

with a grand total at the bottom of the report.

7

8

4.01 Multiple Choice Poll – Correct Answer What is the best description of a detail report?

a. A detail report is a report with over 50 variables and

100 rows.

b. A detail report shows numbers with 12 decimal places.

c. A detail report has a row for every observation in the

data set or subset of data.

d. A detail report contains a row for every observation with a grand total at the bottom of the report.

8

06/03/2016

5

9

Syntax for the REPORT Procedure General form of the REPORT procedure:

Many other SAS statements also work within the context

of a PROC REPORT step:

9

PROC REPORT DATA=libref.filename NOWD;

RUN;

Examples

TITLE FOOTNOTE

FORMAT LABEL

BY

10

PROC REPORT Statement Options Most options in the PROC REPORT statement alter the overall report appearance or affect how PROC REPORT

statements are executed.

10

PROC REPORT DATA=libref.filename NOWD

SPLIT='#';

Selected PROC REPORT options

NOWD | NOWINDOW SPLIT='/' (default)

CENTER|NOCENTER SPANROWS

STYLE=

06/03/2016

6

11

PROC REPORT Options

11

Option Purpose Destination

NOWD

NOWINDOW

Specifies whether the report should run in noninteractive (batch) mode or in the interactive windowing environment. There is no PROC REPORT interactive window in SAS Enterprise Guide.

All

SPLIT='/' (default)

Specifies a split character. PROC REPORT breaks a column header when it reaches the split character and continues the header on the next line.

All

CENTER

NOCENTER

Specifies whether or not the report should be centered. All

SPANROWS Specifies whether the report should allow a group report item to span multiple rows.

Destinations that support style

STYLE= Specifies style attributes for the report table. Destinations that support style

12

The NOWD Option

12

Option Purpose Destination

NOWD

NOWINDOW

Specifies whether the report should run in noninteractive (batch) mode or in the interactive windowing environment. There is no PROC REPORT interactive window in SAS Enterprise Guide.

All

SPLIT='/'

(default)

Specifies a split character. PROC REPORT breaks a

column header when it reaches the split character and continues the header on the next line.

All

CENTER

NOCENTER

Specifies whether the report should be centered or not. All

SPANROWS Specifies whether the report should allow a group report item to span multiple rows.

Destinations that support

style

STYLE= Specifies style attributes for the report table. Destinations that support

style

06/03/2016

7

13

PROC REPORT and the NOWD Option Use the NOWD option to invoke PROC REPORT

in non-interactive mode and send the report to any open destinations.

13

ods html file='r104d01_simple.html' style=sasweb;

proc report data=employees nowd; title 'Simple PROC REPORT';

run; ods html close;

Partial HTML Output

r104d01

14

The Interactive Report Window You can invoke the interactive Report window in two ways:

Select Solutions � Reporting � Design Report from the

Display Manager pull-down menu.

Submit a SAS program without the NOWD option.

14

ods html file='r104a01_simple.html' style=sasweb; proc report data=employees; . . . more code . . . ods html close;

r104a01

06/03/2016

8

15

Invoking PROC REPORT Interactively

15

If you invoke PROC REPORT without the NOWD option, you open the

interactive REPORT window. You can close the REPORT window by

selecting File ���� Close from the pull-down menu, issuing the END

command, or pressing the F3 function key. Output that goes to the

REPORT window will not go to ODS destinations or the Listing window.

r104a01

16

SAS Enterprise Guide SAS Enterprise Guide cannot open the interactive Report window. All PROC REPORT code submitted in an EG

code node runs in non-interactive (batch) mode.

16

06/03/2016

9

17

Understanding PROC REPORT Defaults By default, PROC REPORT results have these properties:

� The report columns appear in the same order as the order the variables are stored in the data set

(or subset of data).

� The observations appear in the same order as they

are stored in the data set (or subset of data).

� On the report row, numeric values are right-justified

and character values are left-justified.

17

NumericCharacter

18

PROC REPORT Defaults The columns on the report appear in their creation order, from left to right.

18

PROC CONTENTS

variable creation order

PROC REPORT

default column order

. . .

06/03/2016

10

19

PROC REPORT Defaults If the data set or subset has formats and labels

permanently assigned, those are used unless they are overridden in the PROC REPORT step.

19

20

Changing PROC REPORT Defaults One way to change PROC REPORT defaults is to use the LABEL or FORMAT statement in the PROC REPORT step.

20

ods html file='r104d02_simple.html' style=sasweb;

proc report data=employees nowd; label employee_gender = 'Gender'; format employee_birthdate mmddyy10.;

run; ods html close;

r104d02

06/03/2016

11

21

The SPLIT= Option

21

Option Purpose Destination

NOWD

NOWINDOW

Specifies whether the report should run in non- interactive (batch) mode or in the interactive windowing environment. There is no PROC REPORT interactive window in SAS Enterprise Guide.

All

SPLIT='/' (default)

Specifies a split character. PROC REPORT breaks a column header when it reaches the split character and continues the header on the next line.

All

CENTER

NOCENTER

Specifies whether the report should be centered or not. All

SPANROWS Specifies whether the report should allow a group report item to span multiple rows.

Destinations that support style.

STYLE= Specifies style attributes for the report table. Destinations that support style

22

Changing the SPLIT= Option The default character for the SPLIT= option is the slash (/). To change this character, use the SPLIT= option

in the PROC REPORT statement.

22

ods html file='r104d02_split.html' style=sasweb; proc report data=employees nowd split='#';

label employee_gender = 'Employee#Gender' employee_birthdate = 'Birth#Date';

format employee_birthdate mmddyy10.; run; ods html close;

r104d02

06/03/2016

12

23

The CENTER Option

23

Option Purpose Destination

NOWD

NOWINDOW

Specifies whether the report should run in noninteractive (batch) mode or in the interactive windowing environment. There is no PROC REPORT interactive window in SAS Enterprise Guide.

All

SPLIT='/' (default)

Specifies a split character. PROC REPORT breaks a column header when it reaches the split character and continues the header on the next line.

All

CENTER

NOCENTER

Specifies whether the report should be centered or not. All

SPANROWS Specifies whether the report should allow a group report item to span multiple rows.

Destinations that support style

STYLE= Specifies style attributes for the report table. Destinations that support style

24

Using the CENTER Option The CENTER or NOCENTER option in the PROC REPORT statement overrides the value for the CENTER

option in the global OPTIONS statement.

24 r104d02

options center; ods html file='r104d02_nocenter.html' style=sasweb;

proc report data=employees nowd split='#' nocenter;

title '3) Using NOCENTER and SPLIT= Options'; label employee_gender = 'Employee#Gender'

employee_birthdate = 'Birth#Date'; format employee_birthdate mmddyy10.;

run; ods html close;

06/03/2016

13

25

PROC REPORT Statements The statements that you use in the PROC REPORT step

affect specific report items, impact how break processing is handled, or compute new report items.

25

PROC REPORT Statements

COLUMN

DEFINE

RBREAK

BREAK

COMPUTE/ENDCOMP Block 4.3

4.2

4.1

26

PROC REPORT Statements

26

Statement Purpose

COLUMN Declares the report items or data set variables you want in the

report and determines the left-to-right order of the items in the

report table.

DEFINE Specifies how the report items or variables are used in the report.

In addition, you can also assign formats to report items, justify

variable values, and specify how missing values are handled.

RBREAK Performs report break processing and, with the SUMMARIZE

option, inserts a Grand Total report row at the top or bottom of the

report.

BREAK Performs break processing for ORDER or GROUP variables and,

with the SUMMARIZE option, inserts a Subtotal line before or

after the break item.

COMPUTE /

ENDCOMP

block

Provides a mechanism for using DATA step language elements

within PROC REPORT to calculate or modify report items or to

use REPORT-specific statements such as LINE or CALL

DEFINE.

06/03/2016

14

27

The COLUMN Statement

27

Statement Purpose

COLUMN Declares the report items or data set variables you want in the

report and determines the left-to-right order of the items in the

report table.

DEFINE Specifies how the report items or variables are used in the report.

In addition, you can also assign formats to report items, justify

variable values, and specify how missing values are handled.

RBREAK Performs report break processing and, with the SUMMARIZE

option, inserts a Grand Total report row at the top or bottom of the

report.

BREAK Performs break processing for ORDER or GROUP variables and,

with the SUMMARIZE option, inserts a Subtotal line before or

after the break item.

COMPUTE /

ENDCOMP

block

Provides a mechanism for using DATA step language elements

within PROC REPORT to calculate or modify report items or to

use REPORT-specific statements such as LINE or CALL

DEFINE.

28

Syntax for the REPORT Procedure General form of the REPORT procedure with the COLUMN statement:

28

PROC REPORT DATA=libref.filename NOWD;

COLUMN report-item-1 . . . report-item-n; RUN;

06/03/2016

15

29

Building a COLUMN Statement You can use the COLUMN statement to

� declare the report items you want to display or use in the report

� determine the left-to-right order of the items in the

report.

General form of the COLUMN statement:

Report items can be data set variables, statistics, or

computed columns.

29

COLUMN item-1 item-2 item-3 item-4 item-5;

30

Using the COLUMN Statement You can impact the report by changing the order of the columns on the report or displaying only some of the

data columns on the report.

Program r104d02 default columns and column order:

30

Columns and column order determined with COLUMN statement:

r104d03

06/03/2016

16

31

Using the COLUMN Statement This COLUMN statement causes the report table to

contain only the listed columns. The LABEL statement

overrides the default label for Employee_Gender

and all other labels and formats come from what is

permanently defined for the data set (or from defaults).

31

ods html file='r104d03_column.html' style=sasweb; proc report data=employees nowd;

column department employee_gender employee_name salary;

label employee_gender = 'Gender'; run; ods html close;

Partial HTML Output

r104d03

32

COLUMN Statement Feature An additional feature of the COLUMN statement is the ability to specify a text string that will be used as a header

that spans multiple columns. By default, headers are

centered above all the report items in the parentheses.

Syntax model for spanning headers:

32

COLUMN ("Spanning Header1" item-1 item-2)

("Spanning Header2" item-3 item-4);

The header text string can be enclosed

within single or double quotes.

06/03/2016

17

33

Creating Spanning Column Headers A simple change to the previous COLUMN statement

creates spanning headers above the report column headers.

33

column ("Spanning Header1" department employee_gender) ("Spanning Header2" employee_name salary);

r104d03

3434

06/03/2016

18

35

Setup for the Poll Consider the report below. Which COLUMN statement

created this report?

35

column department employee_gender employee_name salary;

column department employee_name employee_gender salary;

column _character_;

a.

b.

c.

36

4.04 Multiple Choice Poll Which COLUMN statement created this report?

a. column department employee_gender

employee_name salary;

b. column department employee_name employee_gender salary;

c. column _character_;

36

06/03/2016

19

37

4.04 Multiple Choice Poll – Correct Answer Which COLUMN statement created this report?

a. column department employee_gender

employee_name salary;

b. column department employee_name

employee_gender salary;

c. column _character_;

37

Report items are placed on the report row in the same

left-to-right order as they are listed in the COLUMN

statement. r104d03

38

Syntax for the REPORT Procedure General form of the COLUMN and DEFINE statements:

38

PROC REPORT DATA=libref.filename NOWD;

COLUMN report-item-1 . . . report-item-n;

DEFINE report-item-1 / <usage and other options>; DEFINE report-item-n / <usage and other options>;

RUN;

06/03/2016

20

39

The DEFINE Statement

39

Statement Purpose

COLUMN Declares the report items or data set variables you want in the

report and determines the left-to-right order of the items in the

report table.

DEFINE Specifies how the report items or variables are used in the report.

In addition, you can also assign formats to report items, justify

variable values, and specify how missing values are handled.

RBREAK Performs report break processing and, with the SUMMARIZE

option, inserts a Grand Total report row at the top or bottom of the

report.

BREAK Performs break processing for ORDER or GROUP variables and,

with the SUMMARIZE option, inserts a Subtotal line before or

after the break item.

COMPUTE /

ENDCOMP

block

Provides a mechanism for using DATA step language elements

within PROC REPORT to calculate or modify report items or to

use REPORT-specific statements such as LINE or CALL

DEFINE.

40

About DEFINE Statement Options DEFINE statement options fit into two categories; each category has its own functionality.

� Usage options specify how the report items or

variables are used in the report.

� Attribute options or specifications enable you to assign labels and formats to report items, specify

style attributes and specify how missing values are handled.

40

06/03/2016

21

41

The DEFINE Statement Usage Options

Usage Options Purpose

DISPLAY Is the default usage for character variables;

displays values as they occur in the data set.

ORDER Defines a variable or report item whose

values will be used to order the rows in the

report.

ANALYSIS

MEAN, MIN,

MAX (and other

statistics)

Is the default usage for numeric variables

and SUM is the default statistic; displays the

values as they occur in the detail report.

COMPUTED Defines a report column that is not part of the

data set but whose values are determined in

a compute block.

41 continued...

42

The DEFINE Statement Usage Options

42

Usage Options Purpose

GROUP Consolidates into one row all observations

from the input data set that have the same

value for the variable. Will have one report

row for each unique value or unique

combination of GROUP variables.

ACROSS Consolidates into one summary column all

observations from the input data set that

have the same value for the variable. Will

have one column for each unique value of

the ACROSS variable(s).

06/03/2016

22

43

DEFINE Statement Attribute Options In addition to the USAGE option in the DEFINE

statement, attribute options, specified in each DEFINE statement, alter the report appearance for a particular

column.

43

DEFINE Statement Attribute Options

'Label' FORMAT=

NOPRINT MISSING

ORDER= STYLE=

44

Selected DEFINE Statement Attribute Options

44

Option Purpose

'Label' Specifies a label for the column header with a quoted string

(either single or double quotes). If a variable label is

permanently assigned, it is the default header.

FORMAT=

F=

Specifies a format for the report column. If a variable format

is permanently assigned, it is the default format.

NOPRINT Controls whether the report item appears on the report.

This option is most frequently used when you want to use

a report item for ordering or calculating a new column, but

you do not need the item itself to appear on the report.

ORDER= Specifies the order for the report item (if it has an ORDER

or GROUP variable usage).

MISSING Considers missing values as valid values for the item.

STYLE= Supplies a statement-level style override that changes the

report item's style attributes.

06/03/2016

23

45

DEFINE Statement Syntax Model When you use the DEFINE statement, a usage option

or an attribute option is required after the slash. DEFINE statement options can be specified in any order after the

slash.

General form of the DEFINE statement:

Selected DEFINE statement examples:

45

DEFINE item-1 / usage <attribute-list>;

DEFINE item-2 / 'Label';

DEFINE item-1 / DISPLAY;

DEFINE item-3 / F=comma9.;

46

Default Variable Usage You need to tell PROC REPORT how you want to use a report item on the report. With a DEFINE statement, you

have extensive control over report type, variable usage,

formats, labels, styles, and keyword statistics.

Without a DEFINE statement,

� the report you generate is usually a detail report

� the default usage for report items that are based on

data set variables is based on the variable type.

46

Variable Type Default Usage Report Defaults

Character DISPLAY Detail report in data set order.

Numeric ANALYSIS Default usage of ANALYSIS implies

the default statistic of SUM on the

subtotal or grand total report rows.

06/03/2016

24

47

The DISPLAY Usage Option

Usage Options Purpose

DISPLAY Is the default usage for character variables; displays

values as they occur in the data set.

ANALYSIS Is the default usage for numeric variables and SUM is

the default statistic.

ORDER Defines a variable or report item whose value will be

used to order the rows in the report.

COMPUTED Defines a report column that is not part of the data set

but whose values are determined in a compute block.

GROUP Consolidates into one row all observations from the input

data set that have the same value for the variable or

report item.

ACROSS Forms column headers across the top of the report with

the values of the ACROSS variable(s).

47

48

Using DEFINE Statement Attribute Options When you create a detail report (DISPLAY usage), DEFINE statement attribute options enable you to

enhance the report or change report defaults.

48

06/03/2016

25

49

The DEFINE Statement Label Option

49

Option Purpose

'Label' Specifies a label for the column header with a quoted string

(either single or double quotes). If a variable label is

permanently assigned, it is the default header.

FORMAT=

F=

Specifies a format for the report column. If a variable format

is permanently assigned, it is the default format.

NOPRINT Controls whether the report item appears on the report.

This option is most frequently used when you want to use

a report item for ordering or calculating a new column, but

you do not need the item itself to appear on the report.

ORDER= Specifies the order for the report item (if it has an ORDER

or GROUP variable usage).

MISSING Considers missing values as valid values for the item.

STYLE= Supplies a statement-level style override that changes the

report item's style attributes.

50

Specifying a Label in the DEFINE Statement Instead of using a LABEL statement, you can specify a report column label in the DEFINE statement. The SPLIT=

character is supported in the DEFINE statement label.

50

proc report data=employees nowd split='#'; column department employee_gender

employee_name employee_birthdate; define department / display 'Dept'; define employee_gender / display 'Gender'; define employee_name / display 'Employee#Name'; define employee_birthdate /display

'Date of#Birth' f=mmddyy10.; label employee_gender = 'Label';

run;

r104d04

The DEFINE statement label overrides a label for the

same variable specified in the LABEL statement.

06/03/2016

26

51

The FORMAT= or F= Option

51

Option Purpose

'Label' Specifies a label for the column header with a quoted string

(either single or double quotes). If a variable label is

permanently assigned, it is the default header.

FORMAT=

F=

Specifies a format for the report column. If a variable format

is permanently assigned, it is the default format.

NOPRINT Controls whether the report item appears on the report.

This option is most frequently used when you want to use

a report item for ordering or calculating a new column, but

you do not need the item itself to appear on the report.

ORDER= Specifies the order for the report item (if it has an ORDER

or GROUP variable usage).

MISSING Considers missing values as valid values for the item.

STYLE= Supplies a statement-level style override that changes the

report item's style attributes.

52

Specifying a Format in the DEFINE Statement You can specify a SAS or user-defined format in the DEFINE statement instead of using a FORMAT statement.

Any format in the DEFINE statement overrides a format in

a FORMAT statement.

52

proc report data=employees nowd split='#'; column department employee_gender

employee_name employee_birthdate salary; . . . more code . . . define employee_birthdate /display

'Date of#Birth' f=yymmddp10.; define salary / analysis f=comma12.; format employee_birthdate date7.

salary dollar12.; run; r104d05

06/03/2016

27

53

The NOPRINT Option

53

Option Purpose

'Label' Specifies a label for the column header with a quoted string

(either single or double quotes). If a variable label is

permanently assigned, it is the default header.

FORMAT=

F=

Specifies a format for the report column. If a variable format

is permanently assigned, it is the default format.

NOPRINT Controls whether the report item appears on the report.

This option is most frequently used when you want to use

a report item for ordering or calculating a new column, but

you do not need the item itself to appear on the report.

ORDER= Specifies the order for the report item (if it has an ORDER

or GROUP variable usage).

MISSING Considers missing values as valid values for the item.

STYLE= Supplies a statement-level style override that changes the

report item's style attributes.

54

Using the NOPRINT Option This report is only for employees in Denmark. It is possible to hide the display of the Employee_Country

column, but still leave it in the COLUMN statement.

54 r104d06

column employee_country department employee_gender employee_name salary;

define employee_country / display noprint;

06/03/2016

28

55

The ANALYSIS Usage Option

Usage Options Purpose

DISPLAY Is the default usage for character variables; displays

values as they occur in the data set.

ANALYSIS Is the default usage for numeric variables and SUM is

the default statistic.

ORDER Defines a variable or report item whose value will be

used to order the rows in the report.

COMPUTED Defines a report column that is not part of the data set

but whose values are determined in a compute block.

GROUP Consolidates into one row all observations from the input

data set that have the same value for the variable or

report item.

ACROSS Forms column headers across the top of the report with

the values of the ACROSS variable(s).

55

56

Numeric Variable Defaults For numeric variables, you need to tell PROC REPORT what statistics should be calculated on summary report

rows. ANALYSIS usage is implied if a statistic keyword

is used after the slash in a DEFINE statement.

56

Analysis Usage Option Examples for Numeric Variables

DEFINE Statement Example Statistic Calculated

DEFINE numvar / ANALYSIS; SUM Statistic

DEFINE numvar / ANALYSIS SUM; SUM Statistic

DEFINE numvar / SUM; SUM Statistic

DEFINE numvar / ANALYSIS MIN; MIN Statistic

DEFINE numvar / MIN; MIN Statistic

DEFINE numvar / ANALYSIS MEAN; MEAN Statistic

DEFINE numvar / MEAN; MEAN Statistic

06/03/2016

29

57

The ORDER Usage Option

Usage Options Purpose

DISPLAY Is the default usage for character variables; displays

values as they occur in the data set.

ANALYSIS Is the default usage for numeric variables and SUM is

the default statistic.

ORDER Defines a variable or report item whose value will be

used to order the rows in the report.

COMPUTED Defines a report column that is not part of the data set

but whose values are determined in a compute block.

GROUP Consolidates into one row all observations from the input

data set that have the same value for the variable or

report item.

ACROSS Forms column headers across the top of the report with

the values of the ACROSS variable(s).

57

58

ORDER Usage The ORDER usage option orders the report rows in the report.

ORDER usage does the following:

� orders the report in ascending order

���� Include the DESCENDING option in the DEFINE statement to force the order to be descending.

� suppresses repetitious printing of the report column values

� orders the data without previous sorting

58

06/03/2016

30

59

Report Example without ORDER Usage

59

Department value on

every report row.

Employee_Gender value

on every report row.

The usage option for Department and

Employee_Gender is DISPLAY for this report.

r104d06

60

ORDER Usage for One Report Item

60

define department / order 'Dept'; define employee_gender / display 'Gender';

Department value on

first report row of the

group.

Repetitious values

suppressed for

other report rows

with the same Department value.

r104d07

06/03/2016

31

61

ORDER Usage on Multiple Report Items If you use the ORDER option on multiple report items,

the items are ordered from left to right.

61

define department / order 'Dept'; define employee_gender / order 'Gender';

r104d07

Employee_Gender is ordered within each

Department value.

62

Reviewing the Report Data values are displayed in ascending order, by default.

62

define department / order 'Dept'; define employee_gender / order 'Gender';

Ascending order for Department and

Employee_Gender

values.

r104d07

06/03/2016

32

63

The DESCENDING Attribute Option Use the DESCENDING option in the DEFINE statement.

Only the variable with the DESCENDING option is affected.

63

Top of table

Bottom of table

define department / order descending 'Dept'; define employee_gender / order 'Gender';

r104d07

6464

06/03/2016

33

65

Setup for the Poll Consider this partial HTML

report output. It was created with a PROC REPORT step

which contains this

COLUMN statement:

65

column department employee_gender employee_name salary;

66

4.06 Multiple Choice Poll What is the usage for the first two variables (Department

and Employee_Gender) on the report?

Hint: A usage of DISPLAY does not suppress the display

of repetitious variable values.

a. Department – ORDER and

Employee_Gender – ORDER

b. Department – DISPLAY and Employee_Gender – ORDER

66

06/03/2016

34

67

4.06 Multiple Choice Poll – Correct Answer What is the usage for the first two variables (Department

and Employee_Gender) on the report?

Hint: A usage of DISPLAY does not suppress the display

of repetitious variable values.

a. Department – ORDER and

Employee_Gender – ORDER

b. Department – DISPLAY and

Employee_Gender – ORDER

67

column department employee_gender employee_name salary;

define department / display 'Dept'; define employee_gender / order 'Gender';

r104d07

68

The ORDER= Attribute Option

68

Option Purpose

'Label' Specifies a label for the column header with a quoted string

(either single or double quotes). If a variable label is

permanently assigned, it is the default header.

FORMAT=

F=

Specifies a format for the report column. If a variable format

is permanently assigned, it is the default format.

NOPRINT Controls whether the report item appears on the report.

This option is most frequently used when you want to use

a report item for ordering or calculating a new column, but

you do not need the item itself to appear on the report.

ORDER= Specifies the order for the report item (if it has an ORDER

or GROUP variable usage).

MISSING Considers missing values as valid values for the item.

STYLE= Supplies a statement-level style override that changes the

report item's style attributes.

06/03/2016

35

69

Other Ordering Methods In addition to the ORDER usage option, the ORDER=

attribute option or specification can also impact the display of ORDER (and GROUP) usage report items.

The default value for the ORDER= option in PROC

REPORT is ORDER=FORMATTED.

69

70

ORDER= Syntax Model You can use the ORDER= option only on report items which have a usage of ORDER, GROUP, or ACROSS.

General form of the ORDER= option:

Possible values for the ORDER= option:

70

DEFINE item-1 / ORDER ORDER=<value>;

ORDER= value Default Ordering

DATA input data set order

FORMATTED ascending formatted values

FREQ ascending frequency count

INTERNAL unformatted values

06/03/2016

36

71

Using the ORDER= Option Consider the following

partial list of employees and their birth years in the

Denmark subset of

employees. Note that the

first observation in the file

is for someone born in

1954, then 1986, then

1964, and so on.

71 r104d08

72

ORDER=DATA

72

define employee_birthdate / order order=data 'Birth#Year' f=year4.;

1954 was the first

birth year in the data.

1986 was the second

birth year in the data.

r104d08

1964 was the third

birth year in the data.

06/03/2016

37

73

ORDER=FORMATTED ORDER=FORMATTED is the default

order for PROC REPORT. The order for the birth years is the ascending

formatted value order.

73

define employee_birthdate / order order=formatted 'Birth#Year' f=year4.;

r104d08

74

ORDER=FREQ ORDER=FREQ orders by ascending frequency count (lowest to highest).

So, 1976 (with one person) is first

followed by 1974 (with two people) followed by 1979 (three people), and so on. Since 1979 and 1984 both

have three people, 1979 appears first because it appears before 1984 in the data.

74

define employee_birthdate / order order=freq 'Birth#Year' f=year4.;

r104d08

06/03/2016

38

75

ORDER=INTERNAL ORDER=INTERNAL orders values by their unformatted

values.

75

define employee_birthdate / order order=internal 'Birth#Year' f=year4.;

Without SORT

With SORT

r104d08

7676

06/03/2016

39

77

Chapter Review 1. Why do you use the NOWD option with PROC

REPORT?

2. A data set contains information for 100 employees

who work in 5 departments. A report created from this

data contains 106 report rows, one row for every

employee, a subtotal row for every department and a

grand total row. Is this a detail or summary report?

3. What is the default SPLIT character in PROC

REPORT and how do you use it?

4. What statement arranges the order of items on a

report row?

77

Data managment weeks/week 9/Exercises.docx

Exercisesc:\Program Files\PowerServ\CourseGraphics\exer_arrow.jpg

Level 1

1. Using the COLUMN and DEFINE Statements to Produce a Detail Report

a. Modify starter program r104e01 to produce a detail report for employees in France. Display the following variables: Employee_Country, Department, Org_Group, and Employee_Name. Use the column headers shown in the screen shot of the desired output.

Partial Desired Results

Level 2

2. Changing DEFINE Statement Defaults

a. Modify starter program r104e02 to produce a seniority report based on hire year for a subset of Orion employees in France. Display the following variables: Org_Group, Employee_Hire_Date, and Employee_Name. Use the column headers and variable format YEAR4. for Employee_Hire_Date as shown in the screen shot of the desired output.

Partial Desired Results

Level 3

3. Researching Additional PROC REPORT Options

This Level 3 exercise discovers some of the less frequently used options available with PROC REPORT.

a. Look up the purpose of the NOHEADER option in the PROC REPORT statement.

b. Modify the starter program r104e03 to use the NOHEADER option and produce these results:

c. List the options that control statistical analysis with PROC REPORT.