Storing and Manipulating Data
Julie Kezik, Melissa Hill
Abstract
Julie Kezik, Melissa Hill
Abstract
In this chapter we will learn about storing and manipulating data in SAS, by considering the structure of datasets and the characteristics of variables. We begin with a description of how to access existing data using the SAS specific library convention, including an overview of the different types of storage SAS offers. The Data step is introduced as the primary method for data manipulation in SAS, punctuated with plenty of sample syntax and illustrative figures providing the user with a thorough understanding of what the Data step can do for a programmer. We then move to variable creation and manipulation including an overview of functions and different ways to transform numeric and character variables. LIBRARIES, LIBRARY REFERENCES, AND THE LIBNAME STATEMENT SAS stores and creates data using a library convention. Libraries are a way to call upon a location within the computer by labeling it with a single letter or phrase for the duration of the SAS session. This allows the user a time-saving alternative to repeating a lengthy path name in multiple places. When pulling data from a shared server, the path can include several folders to navigate through before locating the file, for example ‘Z:\JK\SAS 2014\Paper2019\Datasets\final’. Example 3.1, a LIBNAME statement allows the programmer to write the path once, assigning it the library reference (libref) ‘x.’ This libref can be used to locate any SAS dataset in that particular folder for the entirety of the SAS session. Library References can consist of one to eight characters and must begin with a letter, a through z, or an underscore (_); remaining characters may consist of letters, numbers, or underscores. EXAMPLE 3.1. LIBNAME Statement Syntax. libname x ‘Z:\JK\SAS 2014\Paper2019\Datasets\final’; One way to view a dataset within an active library is to toggle to the explorer tab and click on the ‘Libraries’ folder (Figure 3.1). SAS will always show three active libraries, ‘Sashelp’, ‘Sasuser’, and ‘Work.’ The library ‘X’ was created in Example 3.1 using a libname statement. While the libref ‘X’ is a temporary shortcut for accessing a specific location, any dataset written to that location using the libref is stored there permanently. By double-clicking on the desired folder we are able to view its contents. When we open a library in the Explorer window, SAS automatically displays all SAS version 8 or higher datasets stored in that location.
A significance statement is not available in the OpenAlex record.
A contribution statement is not available in the OpenAlex record.
Method details are not available in the OpenAlex metadata.
Findings are not separately available in the OpenAlex metadata.
Limitations are not available in the OpenAlex metadata.
Application details are not available in the OpenAlex metadata.
In this chapter we will learn about storing and manipulating data in SAS, by considering the structure of datasets and the characteristics of variables. We begin with a description of how to access existing data using the SAS specific library convention, including an overview of the different types of storage SAS offers. The Data step is introduced as the primary method for data manipulation in SAS, punctuated with plenty of sample syntax and illustrative figures providing the user with a thorough understanding of what the Data step can do for a programmer. We then move to variable creation and manipulation including an overview of functions and different ways to transform numeric and character variables. LIBRARIES, LIBRARY REFERENCES, AND THE LIBNAME STATEMENT SAS stores and creates data using a library convention. Libraries are a way to call upon a location within the computer by labeling it with a single letter or phrase for the duration of the SAS session. This allows the user a time-saving alternative to repeating a lengthy path name in multiple places. When pulling data from a shared server, the path can include several folders to navigate through before locating the file, for example ‘Z:\JK\SAS 2014\Paper2019\Datasets\final’. Example 3.1, a LIBNAME statement allows the programmer to write the path once, assigning it the library reference (libref) ‘x.’ This libref can be used to locate any SAS dataset in that particular folder for the entirety of the SAS session. Library References can consist of one to eight characters and must begin with a letter, a through z, or an underscore (_); remaining characters may consist of letters, numbers, or underscores. EXAMPLE 3.1. LIBNAME Statement Syntax. libname x ‘Z:\JK\SAS 2014\Paper2019\Datasets\final’; One way to view a dataset within an active library is to toggle to the explorer tab and click on the ‘Libraries’ folder (Figure 3.1). SAS will always show three active libraries, ‘Sashelp’, ‘Sasuser’, and ‘Work.’ The library ‘X’ was created in Example 3.1 using a libname statement. While the libref ‘X’ is a temporary shortcut for accessing a specific location, any dataset written to that location using the libref is stored there permanently. By double-clicking on the desired folder we are able to view its contents. When we open a library in the Explorer window, SAS automatically displays all SAS version 8 or higher datasets stored in that location.
Key concepts: Programmer, Computer science, Syntax, Data manipulation language, Sample (material), Variable (mathematics), Data structure, Data type