The Dataset Attribute Family of Classes

This presentation will specifically present the dataset attribute family, an abstract parent and its twenty-five children. This family of classes provides information on and from SAS® datasets, and the structure is based on the Analysis Matrix design pattern (Shalloway and Trott, 2002). The structure is of generic utility for any application which accesses SAS datasets. Extensive experience with classes or objects or design patterns (Gamma, et. al., 1995) is not necessary for this talk, but the presentation assumes knowledge of how to code a class and instantiate an object with SCL. The core techniques apply to any operating system and any object-oriented language. INTRODUCTION To assist states and countries in developing and maintaining their comprehensive tobacco prevention and control programs, the Centers for Disease Control (CDC) developed the Youth Tobacco Surveillance System (YTSS). The YTSS includes two independent surveys, one for countries and one for American states. A SAS/AF® application was developed to manage and process these surveys. During a four year period, over 1,000,000 surveys have been processed for 35 states and 100 international sites (from 60 countries). This application has been previously documented, both in terms of overall development (Tabladillo, 2003b) and class structure (Tabladillo, 2003a). In summary, during its lifetime, the application grew from zero to forty-four classes. This presentation will specifically define and describe the dataset attribute family, an abstract parent and its twenty-four children, a family developed to automate many common dataset handling functions and sequences within SCL. DATASET ATTRIBUTE OVERVIEW Twenty-five of 44 classes in the current application are part of the dataset attribute family. The single parent class is called DATASET_ATTR and given a dataset ID (or number), it will determine the core dataset characteristics from the SCL ATTRC and ATTRN commands, and store the results in object variables. The five methods are 1) create a new dataset, 2) open an existing dataset, 3) update an existing dataset, 4) close a dataset, and 5) delete a dataset. The subclasses inherit the parent’s functionality using the optional EXTENDS command on the CLASS statement. Each of the 24 subclasses refers to a different type of dataset. For example, the class DATASET_ATTR_LAYOUT refers to the questionnaire, and DATASET_ATTR_DATA refers to the initial survey data. Inside these subclasses, the variable numbers are determined for the standardized list of expected variable names. Some variables are required to run processes, and other variables are optional (if included, they will trigger certain processes). These subclasses retain the results from the VARNUM command in object variables. For example, putting the survey questionnaire layout in its own class allows the developer to define two objects for the same type of dataset (a layout) and possibly do something with these two layouts together. The application compares the standardized master layout with the region-specific (typically customized) layout for inconsistencies during customization. One subclass of general use is called DATASET_ATTR_PROCFREQ and was created specifically to read the standard output dataset generated by proc freq. Both the count and the percent are kept as object variables when the object is presented with a valid dataset ID. Though there are 23 different declared types of datasets (adding the generic type makes 24 classes), future subclasses could easily be added by subclassing the parent class, and then customizing the subclass attributes and functions to reflect the structure of the new dataset. The family relationship most closely matches the Strategy design pattern (Gamma, et. al., 1995), with the common overridden method being the one described by the datasetID attribute. Gamma, et. al., 1995 summarize the Strategy design pattern as follows: Strategy (page 315) Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. (inside cover) The dataset attribute family describes the different strategies available, with each subclass having a different set of methods (a different “algorithm”) unique to that dataset. BASE FUNCTIONS: ATTRN AND ATTRC The dataset attribute family started with the desire to systematically include the information made possible by the SCL commands ATTRN and ATTRC. These two commands return attributes for a SAS table (or dataset). ATTRN returns numeric attributes and ATTRC returns character attributes. The following table summarizes the information available through these commands (for version 8); all the attributes are listed because all the attributes were coded into the dataset attribute base abstract class: Attributes for the ATTRC Function 'CHARSET' -returns a string indicating the character set of the machine that created the SAS table 'ENCRYPT' -returns 'YES' or 'NO' depending on whether the SAS table is encrypted. 'ENGINE' -returns the name of the engine used to access the SAS table. 'LABEL' -returns the label assigned to the SAS table. 'LIB' -returns the libref of the SAS data library in which the SAS table resides. 'MEM' -returns the name of the SAS data library member. 'MODE' -returns the mode in which the SAS table was opened 'MTYPE' -returns the type of the SAS data library member. 'SORTEDBY' -returns an empty string if the SAS table is not sorted. Otherwise, returns the names of the BY columns in the standard BY statement format. 'SORTLVL' -returns an empty string if the SAS table is not sorted. Otherwise, returns a code indicating sort. 'SORTSEQ' -returns an empty string if the SAS table is sorted on the native machine or if the sort collating sequence is the default for the operating system. Otherwise, returns the name of the alternate collating sequence that is used to sort the file. 'TYPE' --is the SAS table type. Attributes for the ATTRN Function 'ANY' -specifies whether the table has rows or columns. 'ALTERPW' -indicates whether a password is required in order to alter the SAS table. 'ANOBS' -indicates whether the engine knows the number of rows. 'ARAND' -indicates whether the engine supports random access. 'ARWU' -indicates whether the engine can manipulate files. 'CRDTE' -returns the SAS table creation date. The value returned is the internal SAS DATETIME value for the creation date. Use the DATETIME format to display this value. 'GENMAX' -returns the maximum number of generations. 'GENNEXT' -returns the next generation number to generate. 'ICONST' -returns information on the existence of integrity constraints for a SAS table. 'INDEX' -indicates whether the SAS table supports indexing. 'ISINDEX' -indicates whether the SAS table is indexed. 'ISSUBSET' -indicates whether the SAS table is a subset. 'LRECL' -returns the logical record length. 'LRID' -returns the length of the record ID. 'MODTE' -returns the last date and time the SAS table was modified. Use the DATETIME format to display this value. 'NDEL' -returns the number of deleted rows in the SAS table. 'NLOBS' -returns the number of logical rows (those not marked for deletion). An active WHERE clause does not affect this number. 'NLOBSF' -returns the number of logical rows (those not marked for deletion) that match the active WHERE clause. 'NOBS' -returns the number of physical rows (including those marked for deletion). An active WHERE clause does not affect this number. 'NVARS' -returns the number of columns in the SAS table. 'PW' -indicates whether a password is required in order to access the SAS table. 'RADIX' -indicates whether access by row number is allowed. 'READPW' -indicates whether a password is required in order to read the SAS table. 'TAPE' -indicates whether the SAS table is a sequential tape file. 'WHSTMT' -returns information about active WHERE clauses. 'WRITEPW' -indicates whether a password is required in order to write to the SAS table. In practical use, most of the above table is not accessed. However, coding all the options into the parent class allows future possible use. FIVE CORE METHODS There are five core methods in the dataset family attribute classes. The five methods are 1) create a new dataset, 2) open an existing dataset, 3) update an existing dataset, 4) close a dataset, and 5) delete a dataset. The first three methods are based on the OPEN command, the fourth based on the CLOSE command, and the last based on the DELETE command. Probably the most used method is the OPEN method, which opens a dataset in the default “input” mode (meaning that values can be read but not modified). Here is the code for that specific method. OPENDATASET:public method inputLibnameDataset:INPUT:CHAR return=num