Skip to main content Accessibility help
×
Hostname: page-component-848d4c4894-ndmmz Total loading time: 0 Render date: 2024-05-19T02:13:44.969Z Has data issue: false hasContentIssue false

Chapter 3 - Storing and Manipulating Data

Published online by Cambridge University Press:  05 June 2016

Julie Kezik
Affiliation:
Yale School of Public Health
Melissa Hill
Affiliation:
Cd3 Inc., Austin, Texas
Get access

Summary

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.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2016

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

Available formats
×