Click the check box of any column to select it—it will be displayed in the table. If a column is already selected, you can deselect it if you uncheck it.
● Click the check box of one column, hold down the Shift key and click the check box of another column. All columns from the first to the last will be selected.
In Figure 4.12 (below), columns for Sex, Height, Weight, Diastolic (diastolic blood pressure), and Systolic (systolic blood pressure) were selected.
Figure 4.12: Selecting Variables
Conclusion
In this chapter, you saw how to find built-in SAS Studio tasks, and you learned how to select data sets from the SASHELP library. The next step is to perform these operations on your own data. Chapter 5 shows you how to import data from Excel workbooks or CSV files and create SAS data sets.
Chapter 5: Importing Data into SAS
Importing Data from an Excel Workbook
Importing an Excel Workbook with Invalid SAS Variable Names
Importing an Excel Workbook That Does Not Have Column Headings
Importing Data from a CSV File
Shared Folders (Accessing Data from Anywhere on Your Hard Drive)
Introduction
Now that you have learned how to perform operations on built-in SASHELP data sets, it’s time to see how to import your own data into a SAS library.
SAS data sets contain two parts: the first part is called the data descriptor, also known as metadata. Metadata is a fancy word for data about your data. In the case of a SAS data set, this portion of the data set contains such information as the number of rows and columns in the table, the column names, the data type for each column (SAS has only two data types—character and numeric), and other information about when the data set was created.
The second part of a SAS data set contains the actual data values. If you tried to examine a SAS data set using another program such as Word or Notebook, it would show up as nonsense. Only SAS can read, write, and analyze data in a SAS data set. If you have data in Excel workbooks or text files, you need to convert that data into a SAS data set before you can use SAS to modify or analyze the data.
In this chapter, you will see how easy it is to import your own data from Excel workbooks, CSV files, and many other file formats such as Microsoft Access and SPSS, and create SAS data sets.
Exploring the Utilities Tab
Start by clicking the Tasks and Utilities tab in the navigation pane. It looks like this.
Figure 5.1: The Tasks and Utilities Tab in the Navigation Pane
When you click this tab, you see three separate tabs, one labeled My Tasks, another labeled Tasks, the last labeled Utilities. Expanding the Utilities tab displays three sub-tabs: Import Data, Query, and SAS Program. (See Figure 5.2 below.)
Figure 5.2: Expanding the Utilities Tab
The Import Data task is used to import data in a variety of formats and to create SAS data sets. A complete list of supported file types is shown in Figure 5.3.
Figure 5.3: List of Supported Files
As you can see in Figure 5.3, this import data utility can import data from many of the most common PC data formats. Because Excel workbooks and CSV files are so popular, let’s use them to demonstrate how SAS converts various file formats into SAS data sets.
Importing Data from an Excel Workbook
Your virtual machine is running a Linux operating system where naming conventions for files are different from the naming conventions used on Microsoft or Apple computers. Filenames in Linux are case sensitive, and folders and subfolders are separated by forward slashes. Filenames on Microsoft platforms are not case sensitive, and folders and subfolders are separated by backward slashes. To help resolve these file-naming conventions, you set up shared folders in your virtual machine that allow your SAS programs to read and write files to the hard drive on your computer.
There are slight differences in how you create shared folders, depending on whether you are running VirtualBox, VMware Workstation Player, or VMware Fusion. The easiest way to read and write data between your SAS Studio session and your hard drive is to place your data files in a specific location on your Windows hard drive—\SASUniversityEdition\myfolders. If you followed the installation directions for your choice of virtualization software, this location on your hard drive is mapped to a shared folder called /folders/myfolders in SAS Studio.
For most of the examples in this book, the location c:\SASUniversityEdition\myfolders is the folder where your data files and SAS data sets are located. All the programs and data files that you place in \SASUniversityEdition\myfolders will show up when you click the My Folders tab in the Navigation pane. Remember that this folder (or an equivalent folder on other operating systems) was created when you installed and configured SAS University Edition.
Let’s use the workbook Grades.xlsx (located in the folder c:\SASUniversityEdition\myfolders) for this demonstration.
If you go to the SAS author site (support.sas.com/cody) and scroll down to this book, you will see some choices listed, including one that reads, “Example Code and Data.” If you click on this link, you can download a ZIP file that contains some programs and data sets. Find the program Create_Datasets.sas and extract it. If you are using SAS Studio with SAS University Edition, a good place to put the files that you downloaded is in a folder called:
c:\SASUniversityEdition\Myfolders
It you do that, you can access the programs and data in the Server Files and Folders tab on the left side of the navigation screen.
Next, open up SAS Studio. In the option to edit the Autoexec.sas file (click on the icon to the left of the question mark (?) on the top line of SAS Studio and select “Edit Autoexec File”), add a line similar to the one below:
libname Stats ‘/folders/Myfolders’;
If you are using SAS Studio in another environment (such as the SAS Windowing Environment or SAS on Demand), you will be placing your files in different locations and modifying the LIBNAME statement shown above.
If you open this workbook in Excel, it looks like this.
Figure 5.4: Excel Workbook Grades.xlsx