What`s on Your Menu?

NESUG 2011
Coders' Corner
What’s on your menu?
Sanjaya Kumar, New York State Department of Health, Tory, NY
Abstract:
This presentation will show how base SAS® can be used in creating a user friendly menu
for hospital admissions data to compute various indicators and measures. The program
can use the variables in multiple formats, based on user input, and uniformly rename the
variables to link with population data from US Census bureau. As part of the CDCfunded New York State Environmental Public Health Tracking (EPHT) project, the New
York State Department of Health (NYSDOH) is developing a surveillance system that
links and displays environmental hazard, health outcome, and sociodemographic data. A
menu driven SAS program is being developed to produce nationally consistent health
data for asthma and myocardial infarction hospital admissions.
This program will show the effectiveness of %WINDOW and its ability to pass user
defined input values for several of the SAS program components. This presentation will
demonstrate the step-by-step process for exploring various SAS features and is intended
for SAS users who have basic SAS knowledge and want to learn more about creating
applications using %WINDOW, Output Delivery System (ODS) and the Dynamic Data
Exchange (DDE).
Introduction:
This presentation provides an overview of developing an interface for gathering the user
input in a dialog format and passing the information to SAS® program for creating
customized output in several user friendly formats without user having to know much
about the SAS program. The program requires only the BASE SAS® to generate the
step-by-step dialogs for user interaction and input. The program can also create output in
pdf, csv, MS Excel, XML and several other formats using the Output Delivery System
(ODS) methods.
Each participating state in the EPHT program has its own variable naming and coding
convention and that makes it difficult to write one SAS program to address the variability
in variable names and formats. Also if there is a need to change the SAS code for various
reasons such as order of variables in the final output, colors schema as well as coding
system for the final nationally consistent data and measures, it is essential to make sure
that each state is creating the output based on most recent changes for the final output.
The use of %WINDOW comes handy in addressing the need for developing a SAS
program that can generate the similar output from hospital admission data from several
states with different variable names, formats and coding system.
%WINDOW is used for developing an interactive user menu to provide the flexibility of
entering information for creating a customized output in a specific format at user specific
location. Additionally, the user input for variable names and format are saved as a text
file along with SAS programs. These values can be changed and the program has the
flexibility of using more than one text files to run the same SAS program. Since the user
entered parameters are saved as a text file, user does not need to modify the SAS code to
NESUG 2011
Coders' Corner
create the output. The program has a total of 11 separate SAS program files that are
called based on user selection in the menu window, shown below.
The Menu!
Health Indicator menu is a simple interface displayed by using the %WINDOW and
%DISPLAY statements to display a predefined macro window. After user enters the
information at a specified place in the macro window and indicates that input is complete
by pressing ENTER key, the requested SAS code is submitted for processing and creating
the required output.
Each of the options (#1 through #9) in the above menu is associated with a SAS program
file that is executed after user enters the selection in the above menu screen. The SAS
program for the menu starts with a %WINDOW statement that includes window title,
attributes, line number and position for each entry, and macro variable name to hold the
information entered by the user. The basic syntax of %WINDOW macro is as follows:
%WINDOW window_name <window name>
COLOR=<color value>
IROW=<initial row value>
ICOLUMN=<initial column value>
ROWS=<# of rows to display>
COLUMNS=<# of columns to display>
#<pointer to start at row#>
@<pointer to start at
column#>
"<prompts for user>"
ATTR=<attributes for prompt eg. rev_video>
+<number of blank spaces>
<declared macro variable name>
REQUIRED=<yes|no> PROTECT=<yes|no> AUTOSKIP=<yes|no>
;
NESUG 2011
Coders' Corner
A part of the SAS code to create the “Health_Indicator” menu window is shown below:
%WINDOW Health_Indicator COLOR=blue IROW=4 ROWS=32 ICOLUMN=10
COLUMNS=90
#2 @22 " Health Indicator Menu" COLOR=YELLOW ATTR=rev_video
#4 @08 "Select to Execute: " COLOR=yellow
#6 @08 "1
Enter parameters and create SAS dataset"
COLOR=white +1 "(Required)" COLOR=CYAN
<< more SAS code >>
#24 @15 youpick 1 ATTR=underline COLOR=white +1 " <-- Type your
selection" COLOR=yellow
;
Second important component of the menu program is %DISPLAY statement that
displays the contents of the %WINDOW statement. Both of these statements can create a
useful, timesaving and interactive SAS program where user does not need to modify the
SAS program to generate a planned output. The syntax for the %DISPLAY statement and
a sample is shown below:
%DISPLAY window_name <window name>
;
The %WINDOW and/or %DISPLAY statements can also be included in a macro:
%MACRO WinMacro <macro name>;
%DISPLAY window_name <window name>;
%MEND WinMacro;
Here is a part if the SAS code for displaying and reading the user input from above
health_indicator window:
%MACRO HIMenu;
%DISPLAY Health_INDICATOR;
%IF &getdata = 1 %THEN %DO;
<< more SAS code >>
%END; %ELSE %DO;
%LET sysmsg=
%upcase(&sysmsg) Is not valid, enter option on line above.;
%display Health_INDICATOR;
%END;
%LET getdata = ;
%MEND HIMenu;
%HIMenu;
One additional feature of the menu program is storing and reading user entered
information in a text file format. This is helpful in eliminating the need for entering the
values for macro variables in SAS program. To run the above program, a text file with
default dummy values is provide with the SAS program and can be edited using Notepad.
as shown below created to hold the macro variables.
NESUG 2011
Coders' Corner
As mentioned earlier, the information about user’s input SAS dataset location, variable
names, and information about creating or using a subset of the input data is important for
generating the required output, it is helpful, if user can store this information in a separate
file and use or modify as needed. Following screen image show dialog created by using
%WINDOW and %DISPLAY statements, for using or creating the attribute information
file. Here user can only enter the information about the file name and it is created in the
same location/directory where the SAS program being used in stored. SAS reads the
directory part using the SYSGET function. It returns the values of the specified
environment variable, SAS-EXECFILEPATH.
TxtPath=%sysget(SAS_EXECFILEPATH);
Once a macro with directory path and file name is created, a new macro without file
name is also created to run additional components of this SAS program:
DATA _null_;
pgmpath=SUBSTR("&TxtPath",1,LENGTH("&TxtPath")-30);
CALL symput("dirpath",TRIM(pgmpath));
RUN;
Following screen image displays the “Load_attribute_information_file” dialog window
that has information about the text file to hold the parameter/attribute information for the
user specific data. User can use the default text file provided with the SAS program or
can create a data specific text file for later use/edit. Once user makes the selection from
the above dialog, next dialog appears to collect/show the parameter/attribute information.
If user has already saved the values for these parameters, SAS program reads it from the
text file specified in the previous dialog and populates the fields. First time user of the
program needs to enter this information that is saved in the text file after verification by
SAS program.
NESUG 2011
Coders' Corner
The SAS code to read the macro variable name and its value from the default/stored
attributed information text file is as follows:
filename attrfile "&dirpath\&var2.";
data _null_; format a $13. b $252.;
infile attrfile dsd dlm="=" missover;
input m v;
call SUMPUTX(m,v);
end;
run;
Where “m” is the macro variable name and “v” is the values of macro variable as
provided in the default attribute information file or as entered by the user.
An important component of a working SAS program is the correct location of input
dataset, variable names and format. Keeping this in mind, this SAS program checks the
location of input and output files, variable names and formats before moving to next step.
If everything is according to the requirements, a dialog confirming the accuracy of the
information appears and gives user and option to change/edit the information before
staring the data processing steps. In case the information entered by user is not correct, a
message indicating the step and the error, in simple language, is displayed at the bottom
of the attribute information collection dialog.
NESUG 2011
Coders' Corner
Input SAS data set location and file name is verified using following SAS code:
%IF %Sysfunc(exist(cdisk.&Urdname)) %THEN %DO;
<<More SAS Code >>
%END;
%else %DO;
%put >>> NOTE FOR THE USER: FILE &UrLib\&Urdname does not exist.
Please check FILE NAME/PATH <<<; /* information in log window */
%DISPLAY Enter_HData_Info.VerifyIP;
%GOTO lblstrt;
%END;
Above %DISPLAY statement is used for displaying the information in %WINDOW
titled “Enter_HData_Info” group title “VerifyIP” as shown below:
%WINDOW Enter_HData_Info
IROW= 1 ICOLUMN= 1 ROWS= 56 COLUMNS= 125 COLOR=WHITE
GROUP=timeinfo
#1 @10 "Hospitalization NCDM Tool" COLOR=MAGENTA a=underline
+3 ": &SYSDAY &SYSDATE9 &SYSTIME."
COLOR=ORANGE
NESUG 2011
Coders' Corner
<<More SAS Code >>
GROUP= VerifyIP
#47 @5 "<> Hospitalization dataset Location (A) OR dataset name
(A1) is incorrect" COLOR=RED a=HIGHLIGHT
/ @5 "Press [ENTER] to correct..."
COLOR=RED a=rev_video
<<More SAS Code >>
;
Verification of variable names is done after checking for the existence of the dataset and
reading the variable names form user input dataset.
%IF %Sysfunc(exist(cdisk.&Urdname)) %THEN %DO;
PROC CONTENTS DATA=cdisk.&UrDName OUT=HVARS(KEEP = varnum name
type format) NOPRINT;
RUN;
PROC TRANSPOSE DATA=HVARS(KEEP=name)
OUT=HVARSL(DROP=_NAME_ _LABEL_) PREFIX=VAR;
var name;
run;
%END;
If the variable names entered by user are matched with the names in input dataset the flag
is set to ‘0’ otherwise the flag gets the preset values for each required variable:
%DO i = 1 %TO &numvars;
%LET varname=%SYSFUNC(varname(&dsid,&i));
%IF &URRaceV EQ 1 OR %SYSFUNC(UPCASE(&varname)) EQ
%SYSFUNC(UPCASE(&URRaceV)) %THEN %LET V4FLAG=4;
%END;
At any point if there is a mismatch, a message is displayed for user to correct the
information. Each required variable has an associated text defined as follows:
%IF &V3FLAG NE 3 %THEN %LET FVAR = PRIMARY DIAGNOSIS variable (A2.);
%ELSE %IF &V4FLAG NE 4 %THEN %LET FVAR = Race variable (A3.);
Value of the macro variable FVAR is associated with a separate group in the
%WINDOW statement and is displayed in the event of unmatched variable name:
GROUP= VerifyV
#47 @5 Fvar COLOR=RED ATTR=REV_VIDEO +1 " is MISSING OR
INCORRECT"
COLOR=RED a=HIGHLIGHT
/ @5 "Press [ENTER] to provide the MISSING information ...."
COLOR=RED a=rev_video
SAS program also checks if the user has provided the required variable names or not.
Each field in the attribute information dialog is defined as required in the %WINDOW
statement and user need to enter either the default value or the variable name. Since each
state has different combination of variables, it is important to provide the flexibility in
using optional variables for the final output. If there is a missing required variable user
gets the feedback by the following GROUP in %WINDOW statement:
NESUG 2011
Coders' Corner
GROUP= VerifyNO
#47 @5 Fvar COLOR=RED ATTR=REV_VIDEO +1 " is required"
COLOR=RED a=HIGHLIGHT
/ @5 "Press [ENTER] to provide at least ONE of these two
variable names ...." COLOR=RED a=rev_video
After the information provided by user is verified, a verification dialog appears where
user gets the option to go back to edit or confirm the information for rest of the SAS
program to run.
Conclusion:
This paper has provided basic concepts that will allow the SAS programmers to get
started in exploring the %WINDOW and %DISPALY statements. Using %WINDOW to
NESUG 2011
Coders' Corner
create an interactive menu is a useful tool in that it lets the user decide upon required
output. These basic techniques provide a foundation upon which more complex program
can be developed.
References:
1. SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition, Cary, NC: SAS
Institute Inc. http://support.sas.com/documentation/cdl_main/
2. %WINDOW: Get the Parameters the User Wants and You Need, Michael A.
Mace, Ins & Outs NESUG 2004
3. Designing User Interface by Using the Macro Facility, Quan Ren, Coder's Corner,
SUGI 1999
4. Obtaining User Criteria Without Editing the Code, Michael A. Mace, NESUG
1998
Acknowledgements:
This work was supported in part by US Department of Health and Human Services,
Centers for Disease Control and Prevention grant U50/CCU422440-03 for Environmental
Public Health Tracking.
Trademark:
SAS ® and all other SAS Institute Inc. product or service names are registered
trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA
registration. Other products and brand names are trademarks or registered trademarks of
their respective owners.
Contact Information:
Your comments and questions are valued and welcome. Please contact the author at:
New York State Department of Health
547 River Street, Room 200
Troy, NY 12180
[email protected]