statguru
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
Example: Creating Dialog Box
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473597.htm
‹#›
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
Exercises
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