SAS Programming 1: Essentials Course Notes PDF
Document Details
Uploaded by Deleted User
2020
Stacey Syphus and Beth Hardin
Tags
Summary
This document is a course notes for SAS® Programming 1: Essentials course. It's about learning SAS programming, including the programming process, accessing and importing data, exploring and validating data, preparing data and analyzing/reporting data. The publisher is SAS Institute Inc. and the preparation date is 26Mar2020.
Full Transcript
SAS® Programming 1: Essentials Course Notes SAS® Programming 1: Essentials Course Notes was developed by Stacey Syphus and Beth Hardin. Additional contributions were made by Bruce Dawless, Brian Gayle, Anita Hillhouse, Marty Hultgren, Mark Jordan, Eva-Maria Kegelmann, Gina Repol...
SAS® Programming 1: Essentials Course Notes SAS® Programming 1: Essentials Course Notes was developed by Stacey Syphus and Beth Hardin. Additional contributions were made by Bruce Dawless, Brian Gayle, Anita Hillhouse, Marty Hultgren, Mark Jordan, Eva-Maria Kegelmann, Gina Repole, Gemma Robson, Samantha Rowland, Allison Saito, Prem Shah, Charu Shankar, Kristin Snyder, Peter Styliadis, Su Chee Tay, and Kitty Tjaris. Instructional design, editing, and production support was provided by the Learning Design and Development team. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are trademarks of their respective companies. SAS® Programming 1: Essentials Course Notes Copyright © 2020 SAS Institute Inc. Cary, NC, USA. All rights reserved. Printed in the United States of America. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, or otherwise, without the prior written permission of the publisher, SAS Institute Inc. Book code E71640, course code LWPG1V2/PG1V2, prepared date 26Mar2020. LWPG1V2_001 ISBN 978-1-64295-937-6 For Your Infor mation iii Table of Contents Lesson 1 Essentials...........................................................................................1-1 1.1 The SAS Programming Process........................................................................1-3 Demonstration: SAS Programming Process...................................................1-6 1.2 Using SAS Programming Tools........................................................................ 1-11 Demonstration: Submitting a SAS Program in SAS Enterprise Guide............. 1-13 Demonstration: Submitting a SAS Program in SAS Studio........................... 1-15 Practice................................................................................................... 1-18 1.3 Understanding SAS Syntax............................................................................. 1-29 Demonstration: Understanding SAS Program Syntax................................... 1-36 Demonstration: Finding and Resolving Syntax Errors................................... 1-39 1.4 Solutions....................................................................................................... 1-43 Solutions to Activities and Questions.......................................................... 1-43 Lesson 2 Accessing Data...................................................................................2-1 2.1 Understanding SAS Data..................................................................................2-3 2.2 Accessing Data through Libraries..................................................................... 2-13 Demonstration: Exploring Automatic SAS Libraries....................................... 2-21 Demonstration: Using a Library to Read Excel Files..................................... 2-25 2.3 Importing Data into SAS.................................................................................. 2-28 Demonstration: Importing a Comma-Delimited (CSV) File............................. 2-31 Practice................................................................................................... 2-35 2.4 Solutions....................................................................................................... 2-38 Solutions to Practices................................................................................ 2-38 Solutions to Activities and Questions.......................................................... 2-39 iv For Your Information Lesson 3 Exploring and Validating Data.............................................................3-1 3.1 Exploring Data.................................................................................................3-3 Demonstration: Exploring Data with SAS Procedures................................... 3-10 Practice................................................................................................... 3-14 3.2 Filtering Rows................................................................................................ 3-18 Demonstration: Filtering Rows with Basic Operators..................................... 3-22 Demonstration: Filtering Rows Using Macro Variables.................................. 3-30 Practice................................................................................................... 3-33 3.3 Formatting Columns....................................................................................... 3-37 Demonstration: Formatting Data Values in Results....................................... 3-41 3.4 Sorting Data and Removing Duplicates............................................................ 3-43 Demonstration: Identifying and Removing Duplicate Values.......................... 3-49 Practice................................................................................................... 3-52 3.5 Solutions....................................................................................................... 3-54 Solutions to Practices................................................................................ 3-54 Solutions to Activities and Questions.......................................................... 3-57 Lesson 4 Preparing Data....................................................................................4-1 4.1 Reading and Filtering Data................................................................................4-3 Practice................................................................................................... 4-12 4.2 Computing New Columns................................................................................ 4-14 Demonstration: Using Expressions to Create New Columns.......................... 4-16 Demonstration: Using Character Functions.................................................. 4-22 Demonstration: Using Date Functions......................................................... 4-26 Practice................................................................................................... 4-28 4.3 Conditional Processing................................................................................... 4-30 Demonstration: Conditional Processing with IF-THEN.................................. 4-31 Demonstration: Processing Multiple Statements with IF-THEN/DO................ 4-42 Practice................................................................................................... 4-46 For Your Infor mation v 4.4 Solutions....................................................................................................... 4-48 Solutions to Practices................................................................................ 4-48 Solutions to Activities and Questions.......................................................... 4-51 Lesson 5 Analyzing and Reporting on Data........................................................5-1 5.1 Enhancing Reports with Titles, Footnotes, and Labels.........................................5-3 Demonstration: Enhancing Reports...............................................................5-9 5.2 Creating Frequency Reports............................................................................ 5-12 Demonstration: Creating Frequency Reports and Grap hs............................. 5-14 Demonstration: Creating Two-Way Frequency Reports................................. 5-17 Practice................................................................................................... 5-19 5.3 Creating Summary Statistics Reports............................................................... 5-23 Demonstration: Creating Summary Statistics Reports................................... 5-24 Practice................................................................................................... 5-30 5.4 Solutions....................................................................................................... 5-33 Solutions to Practices................................................................................ 5-33 Solutions to Activities and Questions.......................................................... 5-36 Lesson 6 Exporting Results................................................................................6-1 6.1 Exporting Data.................................................................................................6-3 Demonstration: Exporting Data to an Excel Workbook....................................6-8 6.2 Exporting Reports........................................................................................... 6-11 Demonstration: Exporting Results to Excel.................................................. 6-15 Demonstration: Exporting Results to PDF.................................................... 6-20 Practice................................................................................................... 6-23 6.3 Solutions....................................................................................................... 6-27 Solutions to Practices................................................................................ 6-27 Solutions to Activities and Questions.......................................................... 6-29 vi For Your Information Lesson 7 Using SQL in SAS®..............................................................................7-1 7.1 Using Structured Query Language (SQL) in SAS................................................7-3 Demonstration: Reading and Filtering Data with SQL.....................................7-9 7.2 Joining Tables Using SQL in SAS..................................................................... 7-13 Demonstration: Joining Tables with PROC SQL........................................... 7-16 7.3 Solutions....................................................................................................... 7-23 Solutions to Activities and Questions.......................................................... 7-23 For Your Infor mation vii To learn more… For information about other courses in the curriculum, contact the SAS Education Division at 1-800-333-7660, or send e-mail to [email protected]. You can also find this information on the web at http://support.sas.com/training/ as well as in the Training Course Catalog. For a list of SAS books (including e-books) that relate to the topics covered in this course notes, visit https://www.sas.com/sas/books.html or call 1-800-727-0025. US customers receive free shipping to US addresses. viii For Your Information Lesson 1 Essentials 1.1 The SAS Programming Process................................................................................... 1-3 Demonstration: SAS Programming Process................................................................ 1-6 1.2 Using SAS Programming Tools.................................................................................. 1-11 Demonstration: Submitting a SAS Program in SAS Enterprise Guide............................ 1-13 Demonstration: Submitting a SAS Program in SAS Studio......................................... 1-15 Practice............................................................................................................... 1-18 1.3 Understanding SAS Syntax........................................................................................ 1-29 Demonstration: Understanding SAS Program Syntax................................................. 1-36 Demonstration: Finding and Resolving Syntax Errors................................................. 1-39 1.4 Solutions................................................................................................................... 1-43 Solutions to Activities and Questions........................................................................ 1-43 1-2 Lesson 1 Essentials Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.1 The SAS Programming Process 1-3 1.1 The SAS Programming Process SAS Programming Language 3 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. It is impossible to understand data without using tools that help you derive meaning from numbers and text. SAS offers a huge collection of tools and solutions to handle all your data needs. At the core of all that SAS offers is the SAS programming language. Regardless of the SAS suite of tools that you licensed, the Base SAS programming language is included. This course teaches you how to write SAS code to handle the most common data processing tasks. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-4 Lesson 1 Essentials SAS Programming Process Analyze and Access Explore Prepare Export report on data data data results data 4 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. As you go through the process of making data meaningful and actionable, you will likely follow these basic steps: access, explore, prepare, analyze and report, and export. SAS has programming tools for each of these steps in the process. You follow this process as you learn the fundamentals of the SAS programming language. SAS Programming Process Analyze and Access Explore Export Prepare data report on data data results data international storm data 5 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. In this class, we analyze mainly international storm data, which is real data about storms such as hurricanes, typhoons, and cyclones that has been collected since 1980. This data is stored in a variety of formats, and the first thing you learn to do is write a SAS program to ac cess the data. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.1 The SAS Programming Process 1-5 SAS Programming Process Analyze and Access Explore Export Prepare data report on data data results data 6 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. As you continue through the programming process, you learn to write SAS programs that turn this data into informative reports, tables, and graphics. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-6 Lesson 1 Essentials SAS Programming Process Scenario Examine the international storm data that is used in course demonstrations. Open and run a SAS program that follows the SAS programming process. The code included in the program is covered throughout this course. Files p101d01.sas Storm.xlsx – a Microsoft Excel workbook containing detail and summary data about international storms Demo (for Instructors Only) Note: The intent of this demo is not to study the specific syntax in the program. The purpose is to see a complete program that addresses the steps of the SAS programming process and view the results created by SAS. The details of the syntax in the program are discussed in subsequent lessons. 1. Start SAS Studio or SAS Enterprise Guide. Open the cre8data.sas program from the course files folder. If necessary, change s:/workshop to the path of your course files folder. Run the program and verify that a report listing 22 SAS tables is created. 2. Start Excel and open Storm.xlsx from the data folder in the course files. Examine each worksheet: a. Storm_Summary contains one row per storm between 1980 and 2016. Wind speeds are measured in miles per hour (MPH). Note: Refer to the Basin_Codes, SubBasin_Codes, and Type_Codes worksheets for the full names of the codes in the respective fields. b. Storm_Detail contains one measurement for every six hours of a storm. Wind speeds are measured in knots. c. Storm_Damage includes a description and damage estimates (adjusted for inflation) for storms in the US with damages greater than one billion dollars. d. Storm_Range contains one row per storm with a minimum of four wind measurements. The top four wind measurements are in columns Wind1 through Wind4. e. Storm_2017 contains one row per storm for 2017. f. Basin_Codes, SubBasin_Codes, and Type_Codes are lookup tables with codes and descriptive values. 3. Close the Storm.xlsx file. 4. In either SAS Studio or SAS Enterprise Guide, open p101d01.sas from the demos folder. 5. Find the section labeled Section 1: Access Data. Highlight the code in Section 1 and run the selected portion of the program. Click Run or press the F3 key. Examine the Output Data tab to view the imported table. The SAS code in this section does the following: a. sets system options Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.1 The SAS Programming Process 1-7 b. establishes the location of the course files and generated results c. connects to the Excel Storm.xlsx data so that it can be used in the program d. creates a temporary copy of the Storm_Damage Excel spreadsheet as a SAS table 6. Click the Code tab. Highlight the code in Section 2 and press F3 to run the selected code. Examine the Results tab to view the reports. The SAS code in this section does the following: a. creates a frequency report to examine the unique values of the Basin and Type columns b. calculates summary statistics for the MaxWindMPH and MinPressure columns c. prints the first five rows from the storm_damage table that was imported from Excel 7. Click the Code tab. Highlight the code in Section 3 and press F3 to run the selected code. Examine the Output Data tab to view the generated tables. The SAS code in this section does the following: a. adds additional storm data from 2017 b. cleans data by correcting case differences and assigning des criptive values to coded values c. creates additional new columns with numeric calculations and character manipulations d. joins tables to combine columns from two tables 8. Click the Code tab. Highlight the code in Section 4 and press F3 to run the selected code. Examine the Results tab to view the reports. The SAS code in this section does the following: a. designates values to subset the data for the report as 2016 and NA (North Atlantic basin) b. generates default reports as well as an Excel workbook with the reports c. creates a frequency report for BasinName for the selected year d. creates a summary statistics report and a table that include statistics for storms in the selected year e. creates a map of storms for the selected year and basin 9. Open the Storm_Report2016.xlsx file in the output folder in the course files and view the results that were created in Excel. a. SAS Studio: Select Files and Folders, navigate to the output folder, and select the Storm_Report2016.xlsx file. Click Download and open the file when you are prompted in your browser. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-8 Lesson 1 Essentials b. Enterprise Guide: Click the Results tab and double-click the Excel file to open the new file. You can also right-click on the file and select Open. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.1 The SAS Programming Process 1-9 Data Used in This Course US National class Park data cars international storm and weather data shoes Europe tourism and trade data 9 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. The detailed international storm data can be found at https://www.ncdc.noaa.gov/ibtracs/index.php?name=wmo-data as part of the International Best Track Archive for Climate Stewardship (IBTrACS). The data has been summarized and cleansed to use in this course. The US National Park data can be found at https://irma.nps.gov/Stats/Reports/National. The data has been summarized and cleansed to use in this course. The Europe tourism data can be found at http://ec.europa.eu/eurostat/data/database. The data has been summarized and cleansed to use in this course. SAS sample tables are provided in the Sashelp library. See https://support.sas.com/documentation/tools/sashelpug.pdf for documentation about the available tables. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-10 Lesson 1 Essentials Practicing in This Course Demonstration Performed by your instructor as an example for you to observe Activity Short practice opportunities for you to perform in SAS, either independently or with the guidance of your instructor Practice Extended practice opportunities for you to work on independently Case Study A comprehensive practice opportunity at the end of the class 10 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Choosing a Practice Level Level 1 Solve basic problems with step-by-step guidance Level 2 Solve intermediate problems with defined goals Challenge Solve complex problems independently Choose one with SAS Help and documentation practice to do in resources class based on your interest and skill level. 11 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.2 Using SAS Programming Tools 1-11 1.2 Using SAS Programming Tools SAS Programming Interfaces SAS Studio SAS Enterprise Guide All these interfaces have the basic tools that you need for programming. SAS windowing environment 13 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. SAS provides several programming interfaces that can be used to interactively write and submit code. SAS Studio – a web-based interface to SAS that you can use on any computer. SAS Studio is the interface that is used in SAS OnDemand for Academics. SAS OnDemand for Academics is cloud-based software. For more information, visit https://www.sas.com/en_us/learn/academic- programs/software.html. SAS Enterprise Guide – a Windows client application that runs on your PC and accesses SAS on a local or remote server. SAS windowing environment – a legacy interface that is part of SAS. Note: This course uses SAS Enterprise Guide and SAS Studio because these are the SAS interfaces that have the most modern programming tools. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-12 Lesson 1 Essentials SAS Programming Interfaces write view and 1 data myclass; view 2 set sashelp.class; messages submit 3 run; results from SAS code NOTE: There were 19 observations read from the data set SASHELP.CLASS. data myclass; NOTE: The data set WORK.MYCLASS has 19 set sashelp.class; observations and 5 variables. run; NOTE: DATA statement used: real time 0.01 seconds proc print data=myclass; cpu time 0.00 seconds run; 4 5 proc print data=myclass; NOTE: Writing HTML Body file: sashtml.htm 6 run; NOTE: There were 19 observations read from the data set WORK.MYCLASS. Editor Log Results and Output Data 14 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. To program, you need some basics: an editor to write and submit code, a way to read messages related to the code that you submit (this is called the log in SAS), and a way to view the reports and data that your programs create. Although they look different and are organized differently, all SAS interfaces have these interactive programming tools. In addition, SAS Studio and Enterprise Guide have an editor that is smart about SAS code, with features such as code completion and syntax coloring. Programs can also be submitted to the operating environment behind the scenes. This is referred to as batch processing or background submit. The log and results are saved by default as separate files in the same location as the SAS program. Background submission is often used for programs that run regular jobs on a routine basis. These programs have typically been tested and can run unattended. SAS Studio also enables you to submit programs by right-clicking a.sas file in the Navigation pane and selecting Background Submit. You can view the status of background programs and access the associated log and results files by clicking the More application options icon and selecting Background Job Status. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.2 Using SAS Programming Tools 1-13 Submitting a SAS Program in SAS Enterprise Guide Scenario Write and submit a simple SAS program in SAS Enterprise Guide and examine the log and results. Files sashelp.class – a sample table provided by SAS that includes information about 19 students Notes Programs can be submitted by clicking Run or pressing the F3 key. A program generates a log. Depending on the code, a program might also generate results and output data. To run a subset of a program, highlight the desired code. Then click Run or press F3. Demo 1. View Sashelp sample tables. Note: Sashelp is a collection of sample data files provided by SAS that are useful for testing and practicing. This course references various data files in Sashelp to illustrate programming syntax. a. Open Enterprise Guide. On the Start Page, click Create a new program. Note: In Enterprise Guide, your work can be organized in projects. To do so, select Create a new project. As you open tables and programs or create new programs, you will notice shortcuts added to your project in the Project pane. The project can be saved by selecting File Save Project. b. In the Servers pane in the lower left corner, expand Servers Local Libraries SASHELP. c. Double-click the CLASS table to open and view the data. You do not need to close the table. 2. Write and submit a program in SAS Enterprise Guide. a. Type or copy and paste the program below on the Program tab and click Run. Note: If the Program tab is not open, select File New Program, or click Create a new item on the toolbar and select Program. Note: If you copy and paste the program, click the Format code button to improve the program spacing. data myclass; set sashelp.class; run; proc print data=myclass; run; Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-14 Lesson 1 Essentials b. Click the Log tab and toggle on the Notes button (if necessary). The log includes the program and messages that are returned from SAS. The Log Summary is displayed by default at the top of the window. You can click any of the messages in the Log Summary to find the message in the log. Note: If the Log Summary is closed, click the drop-down arrow to the right of the Errors, Warnings, and Notes tab to expand the Log Summary. c. Click the Output Data and Results tabs to examine the output. d. Return to the Code tab. Highlight the PROC PRINT and RUN statements and click Run or press F3. Note: In this course, you often need to run only a portion of a SAS program. e. Frequently, it is helpful to view multiple tabs at the same time. For example, you might want to view a program and the results, or possibly compare two tables. By default, SAS Enterprise Guide separates a program's tabs. To view more tabs at the same time, right-click the tab that you would like to view and select either Float, New vertical tab group, or New horizontal tab group. You can also drag and drop tabs outside of Enterprise Guide in any location that you prefer. Note: To return a tab to the original location, right-click the top bar of the tab and select Docked as tabbed document for a Float window, or select Move to previous tab group for a vertical or horizontal tabbed group. You can also set defaults for program sub-tabs by going to View Program tab presets and selecting the preset of your choice. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.2 Using SAS Programming Tools 1-15 Submitting a SAS Program in SAS Studio Scenario Write and submit a simple SAS program in SAS Studio and examine the log and results. Files sashelp.class – a sample table provided by SAS that includes information about 19 students Notes Programs can be submitted by clicking Run or pressing the F3 key. A program generates a log. Depending on the code, a program might also generate results and output data. To run a subset of a program, highlight the desired code and click Run or press F3. When you rerun a program, the existing log, results, and output data are replaced. Demo 1. View Sashelp sample tables. Note: Sashelp is a collection of sample data files provided by SAS that are useful for testing and practicing. This course references various data files in Sashelp to illustrate programming syntax. a. Open SAS Studio. In the navigation pane on the left side of the window, select Libraries. Expand My Libraries SASHELP. b. Double-click the CLASS table to open and view the data. A panel to the left of the data lists the columns in the table. The Column panel can be collapsed by clicking the left-pointing arrow. c. Close the SASHELP.CLASS tab. 2. Write and submit a program in SAS Studio. a. A new program window labeled Program 1 is open. Notice that there are tabs labeled CODE, LOG, and RESULTS. Note: If you do not have a new program window, press F4 or click New in the Files and Folders pane and select SAS Program. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-16 Lesson 1 Essentials b. Type or copy and paste the program below on the CODE tab and click Run. Note: If you copy and paste the program, click the Format code button to improve the program spacing. data myclass; set sashelp.class; run; proc print data=myclass; run; c. Click the LOG tab. The log includes the program and messages returned from SAS. You can expand the Errors, Warnings, or Notes sections to see all messages in a summary list. You can click any of the messages to find the corresponding message in the log. d. Click the RESULTS and OUTPUT DATA tabs to examine the output. Note: To optimize the display of the table on the OUTPUT DATA tab, right-click any of the column headings and select Size grid columns to content. To set this option for all tables, click More application options and then click Preferences. Click the Size grid columns to content check box and click Save. e. Return to the CODE tab. Highlight the PROC PRINT and RUN statements and click Run or press F3. Confirm that the log and results were replaced. f. To view multiple tabs at the same time, click one of the tabs (CODE, LOG, OUTPUT DATA, or RESULTS) and drag it to the side or bottom of the work area until a highlighted region appears. To return to a single window, drag the separated tab back to the main tab area. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.2 Using SAS Programming Tools 1-17 1.01 Multiple Answer Question Which SAS interface will you use in class? a. SAS Enterprise Guide b. SAS Studio 16 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-18 Lesson 1 Essentials Practice Note: Please choose either the SAS Enterprise Guide or SAS Studio practice to further explore your interface of choice. Level 1 – SAS Enterprise Guide 1. Exploring the SAS Enterprise Guide Programming Windows a. Start SAS Enterprise Guide and close the Start Page. Enterprise Guide consists of a navigation area on the left and a work area on the right. b. Select File New Program (or click the Create a new item tool and select Program) to start writing a SAS program. On the Code tab, type or copy and paste the following code. This is a simple SAS program called a DATA step. Note: If you copy and paste the program, click the Format code button to improve the program spacing. data work.shoes; set sashelp.shoes; NetSales=Sales-Returns; run; c. Click Run or press F3 to submit the code. Examine the Log and Output Data tabs. d. Click the Log tab. Notice that there are additional statements included before and after the DATA step. This is called wrapper code, and it includes statements added by Enterprise Guide to set up the environment and results. To make the log easier to read, the wrapper code statements can be hidden. Select Tools Options Results General and clear the Show generated wrapper code in SAS log check box. Click OK. e. Return to the Code tab and rerun the program. Examine the log. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.2 Using SAS Programming Tools 1-19 f. On the Code tab, add code to compute summary statistics. At the end of the program, begin by typing pr. Notice that a prompt appears with valid keywords. Press the Enter key or the spacebar to add the word proc to the program. Press the spacebar and type me. Press Enter again to add means to the program. g. Press the spacebar, use the prompts to select data=work.shoes, and press the spacebar again. Notice that the prompt lists all valid options. Type or select options in the window to complete the following statement: proc means data=work.shoes mean sum maxdec=2; Note: Autocomplete prompts can be modified or disabled by selecting Program Editor options and then clicking the Autocomplete tab. On the tab, you can adjust the prompts. h. Complete the program by adding the highlighted statements below. Notice that after VAR and CLASS, the autocomplete prompt includes a list the columns from the work.shoes table. proc means data=work.shoes mean sum maxdec=2; var NetSales; class region; run; Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-20 Lesson 1 Essentials i. Highlight the code from PROC MEANS through RUN, and select Run or press F3. Note: The default output format in SAS Enterprise Guide is HTML. j. By default, the tabs are a vertical split. To change the default layout view of the program tabs, go to View Program tab presets. You can also right-click a tab and select Float, New vertical tab group, New horizontal tab group, or (if it is available) Move to previous tab group. Note: Options for a single tab. Note: Options for grouped tabs. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.2 Using SAS Programming Tools 1-21 Note: You can also select a tab and drag it to a location of your choice. k. To return to a single window for all program tabs, select View Program tab presets Standard. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-22 Lesson 1 Essentials l. In addition to creating HTML output, you can create other output types. Click the Code tab and click the properties icon. Select Results Customize result formats, styles, and behavior. Clear any selected check boxes and then select the PDF and Excel check boxes. Click OK. m. Run the program again. An Excel file and a PDF file are created on the Results tab. Note: PowerPoint, Excel, PDF, and RTF results must be viewed outside of Enterprise Guide. Double-click the Excel or PDF file to open it. You can also right-click the file and select Open. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.2 Using SAS Programming Tools 1-23 n. To save the program, return to the Code tab and click the Save "Program" As icon. Navigate to the output folder in the course files. Enter shoesprogram in the File name field and click Save. The.sas file extension is automatically added to the file name. Level 1 – SAS Studio 2. Exploring the SAS Studio Editor a. Start SAS Studio. The main window of SAS Studio consists of a navigation pane on the lef t and a work area on the right. b. Options are available in the banner area to customize your SAS Studio environment. Search files and folders. Search Open files from your files and shortcuts. Open New program, new import data, new query, close all tabs, and New Options maximize view. SAS Studio includes two different perspectives: the SAS Programmer perspective and the Visual Programmer perspective. A perspective is a predetermined set of features that is customized to meet the needs of a specific type of user. This course is about programming in SAS, so you need to make sure that the SAS Programmer perspective is selected on the toolbar at the top of the application. You can find more information about both perspectives in SAS Studio User's Guide. More application options, including edit autoexec file, a view menu, More preferences, tool options, background submission status, and reset application options SAS session. A Help menu, including SAS Studio Help, SAS Product Help Documentation, and About SAS Studio. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-24 Lesson 1 Essentials c. On the Program 1 tab, type or copy and paste the following code. This is a simple SAS program called a DATA step. Note: If you copy and paste the program, click Format code to improve the program spacing. data work.shoes; set sashelp.shoes; NetSales=Sales-Returns; run; d. Click Run or press F3 to submit the code. Examine the LOG and OUTPUT DATA tabs. The RESULTS tab is empty because the program did not create a report. e. On the CODE tab, add code to compute summary statistics. At the end of the program, begin by typing pr. Notice that a prompt appears with valid keywords and syntax help. Press Enter to add the word proc to the program. Press the spacebar and type me, and press Enter again to add means to the program. Note: The Autocomplete prompts also include a window with syntax Help and links to documentation and examples. f. Press the spacebar, use the prompt to select data=, and then type work.shoes. Press the spacebar and notice that the prompt lists all valid options. Type or select options in the window to complete the following statement: proc means data=work.shoes mean sum; g. Autocomplete prompts can be disabled by clicking More application options and then clicking Preferences Code and Log. Clear the Enable autocomplete check box and click Save. h. Return to the CODE tab and press the spacebar after the SUM option and before the semicolon. Notice that a prompt does not appear. Type MAXDEC=2 to round statistics to two decimal places. Note: If autocomplete is turned off, you can temporarily toggle it on at any point by holding down the Ctrl key and pressing the spacebar to view the autocomplete prompt. i. Complete the program by adding the following statements : proc means data=work.shoes mean sum maxdec=2; var NetSales; class region; run; Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.2 Using SAS Programming Tools 1-25 j. Highlight the code from PROC MEANS through RUN and click Run or press F3 to run only the selected portion. Confirm the results. Note: The default output format in SAS Studio is HTML. k. To view multiple tabs at the same time, click the RESULTS tab and drag it to the right side of the work area until a highlighted region appears. To return to a single window, drag the RESULTS tab back to the main tab area. l. On the RESULTS tab, click the HTML, PDF, or Word icon to open results in the corresponding file format. You are prompted to open or save the file in the browser. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-26 Lesson 1 Essentials Note: Additional options for the output formats are available by clicking More application options and selecting Preferences Results. m. To save the program, return to the CODE tab and click the Save As toolbar button. Navigate to the output folder in the course files. Enter shoesprogram in the Name field and click Save. The.sas file extension is automatically added to the file name. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.2 Using SAS Programming Tools 1-27 Accessing the Course Files course files activities Make a note of data the location of your course files demos folder. practices output 18 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Accessing the Course Files Programs in the activities, demos, course and practices files folders follow this activities naming convention. data demos practices p104d01.sas Programming 1, Lesson 4, demo 1 output 19 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-28 Lesson 1 Essentials Creating the Course Data course files activities data cre8data.sas demos practices output 20 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. 1.02 Activity (Required) 1. SAS Studio: In the Navigation pane, expand Files and Folders and then navigate to the course files folder. SAS Enterprise Guide: In the Servers list, expand Servers Local Files, and then navigate to the course files folder. 2. Double-click the cre8data.sas file to open the program. 3. Find the %LET statement. As directed by your instructor, provide the path to your course files. 4. Run the program and verify that a report that lists 22 tables is created. 21 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.3 Understanding SAS Syntax 1-29 1.3 Understanding SAS Syntax SAS Program Structure step data myclass; set sashelp.class; heightcm=height*2.54; step run; proc print data=myclass; A SAS program step run; consists of a proc means data=myclass; sequence of steps.... var age heightcm; run; SAS program 24 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. SAS Program Structure DATA step data myclass; set sashelp.class; heightcm=height*2.54; run; proc print data=myclass; A program can be run; any combination PROC step of DATA and PROC proc means data=myclass; (procedure) steps var age heightcm; run; 25 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-30 Lesson 1 Essentials SAS Program Structure DATA step data myclass; set sashelp.class; heightcm=height*2.54; run; proc print data=myclass; DATA steps run; typically read, process, or create proc means data=myclass; data. var age heightcm; run; 26 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. A DATA step can contain a variety of data manipulations, including filtering rows, computing new columns, and joining tables. In this program, the DATA step is creating a copy of an existing SAS table and adding a new column to convert height from inches to centimeters. SAS Program Structure data myclass; set sashelp.class; heightcm=height*2.54; run; proc print data=myclass; PROC steps run; typically report, PROC step manage, or proc means data=myclass; analyze data. var age heightcm; run; 27 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. A PROC, or procedure, step typically processes a SAS data set. SAS has dozens of procedures that generate reports and graphs, manage data, or perform complex statistical analysis. This program has two PROC steps: PROC PRINT generates a list of all the rows and columns in the data, and PROC MEANS calculates basic summary statistics for age and heightcm. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.3 Understanding SAS Syntax 1-31 SAS Program Structure Steps begin with either DATA or PROC. data myclass; set sashelp.class; heightcm=height*2.54; run; proc print data=myclass; run; This program has three steps. Steps end with RUN. proc means data=myclass; Some PROCs end with var age heightcm; run; QUIT. 28 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. If a RUN or QUIT statement is not used at the end of a step, the beginning of a new step implies the end of the previous step. If a RUN or QUIT statement is not used at the end of the last step, SAS Studio and Enterprise Guide automatically submit a RUN and QUIT statement after the submitted code. SAS Program Structure step data myclass; set sashelp.class; statement; heightcm=height*2.54; statement; run; statement; proc print data=myclass; A step is a run; sequence of SAS step statements. proc means data=myclass; var age heightcm; step run; SAS program 29 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-32 Lesson 1 Essentials SAS Statement Syntax data myclass; set sashelp.class; heightcm=height*2.54; run; Most statements proc print data=myclass; run; begin with a keyword, and all proc means data=myclass; statements end with var age heightcm; a semicolon. run; 30 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Most statements begin with an identif ying keyword. In addition to DATA, PROC, and RUN statements, this program also includes SET and VAR statements. The one statement that does not begin with a keyword is the one that is creating the new column heightcm. The most important thing to remember here is that all statements end with a semicolon. Global Statements TITLE... ; OPTIONS... ; Global statements are typically outside of LIBNAME... ; steps and do not need a RUN statement. 31 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. In addition to DATA and PROC steps, a SAS program can also contain global statements. These statements can be outside DATA and PROC steps, and they typically define some option or setting for the SAS session. Global statements do not need a RUN statement after them. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.3 Understanding SAS Syntax 1-33 1.03 Activity Open p101a03.sas from the activities folder and perform the following tasks: 1. View the code. How many steps are in the program? 2. How many statements are in the PROC PRINT step? 3. How many global statements are in the program? 4. Run the program and view the log. 5. How many observations were read by the PROC PRINT step? 32 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. SAS Program Syntax: Format data myclass;set sashelp.class;run; These are proc print data=myclass;run; the same to SAS. data myclass; set sashelp.class; run; Formatting makes your code easier proc print data=myclass; to read and run; understand. 34 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. These two programs have exactly the same code. Spacing does not matter to SAS, but it does matter to people reading your code. You can use spaces and extra lines to make your program easy to read and understand. There are also tools in your editor that format code for you. Click Format code on the toolbar or right-click in the program and select Format code to format a SAS program. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-34 Lesson 1 Essentials SAS Program Syntax: Case data under13; set sashelp.class; where AGE 35; run; title "Average MPG by Car Type"; proc means data=mycars mean min max maxdec=1; var avgmpg; class type; run; title; Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-40 Lesson 1 Essentials 1.04 Activity Open p101a04.sas from the activities folder and perform the following tasks: 1. Format the program to improve the spacing. What syntax error is detected? Fix the error and run the program. 2. Read the log and identify any additional syntax errors or warnings. Correct the program and format the code again. 3. Add a comment to describe the changes that you made to the program. 4. Run the program and examine the log and results. How many rows are in the canadashoes data? data canadashoes; set sashelp.shoes; where region="Canada; Profit=Sales-Returns;run; prc print data=canadashoes;run; 40 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Extending Your Learning 42 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. The Extended Learning page is designed to supplement your learning for SAS Programming 1. The Extended Learning page includes the following resources: PDF version of the course notes in English and other languages course files case studies for additional practice and application links to papers, videos, blogs, and other resources to learn more about related topics Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.3 Understanding SAS Syntax 1-41 Beyond SAS Programming 1 What if you want to...... use point-and-click... use the SAS... learn about using SAS Studio tasks to windowing environment Enterprise Guide tasks generate code? in this class? to generate code? Watch the video Getting Watch the video Writing and Visit the Learn SAS Started with SAS Studio. Submitting SAS Code: Enterprise Guide page View additional free Choosing an Editor. for videos, tutorials, and video tutorials on using Complete the SAS windowing training. SAS Studio tasks. environment activity on the Take the SAS Enterprise Extended Learning Page. Guide 1: Querying and Reporting course. 43 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Links Watch the video Getting Started with SAS Studio. View additional free video tutorials about using SAS Studio tasks. Watch the video Writing and Submitting SAS Code: Choosing an Editor. Visit the Learn SAS Enterprise Guide page for videos, tutorials, and training. Take the SAS Enterprise Guide 1: Querying and Reporting course. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-42 Lesson 1 Essentials Beyond SAS Programming 1 What if you want to...... use Jupyter... write code to take... integrate open Notebook to submit advantage of cloud- source languages with code to SAS? enabled SAS Viya? SAS? Read the blog post How Watch the video An Take the free SAS to run SAS programs in Introduction to SAS Viya Programming for R Jupyter Notebook. Programming for SAS 9 Users course. Read the instructions Programmers. Read the Getting and download Jupyter Take the Programming for Started with SAS Viya kernel for SAS on the SAS Viya course after SAS for R documentation. SAS github page. Programming 1. 44 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Links Read the blog post How to run SAS programs in Jupyter Notebook. Read instructions and download Jupyter kernel for SAS on the SAS GitHub page. Watch the videos on An Introduction to SAS Viya Programming for SAS 9 Programmers. Take the Programming for SAS Viya course after SAS Programming 1. Take the free SAS Programming for R Users course. Use the Getting Started with SAS Viya for R documentation. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1.4 Solutions 1-43 1.4 Solutions Solutions to Activities and Questions 1.02 Activity – Correct Answer Confirm that 22 SAS tables were created. 22 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. 1.03 Activity – Correct Answer Open p101a03.sas from the activities folder and perform the following tasks: 1. View the code. How many steps are in the program? There are three steps: one DATA step and two PROC steps. 2. How many statements are in the PROC PRINT step? four statements 3. How many global statements are in the program? three TITLE statements 4. Run the program and view the log. 5. How many observations were read by the PROC PRINT step? 11 observations 33 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 1-44 Lesson 1 Essentials 1.04 Activity – Correct Answer How many rows are in the canadashoes data? 37 data canadashoes; Formatting the set sashelp.shoes; code identifies the where region="Canada"; missing quotation Profit=Sales-Returns; mark. run; proc print data=canadashoes; run; 41 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. Lesson 2 Accessing Data 2.1 Understanding SAS Data............................................................................................. 2-3 2.2 Accessing Data through Libraries.............................................................................. 2-13 Demonstration: Exploring Automatic SAS Libraries.................................................... 2-21 Demonstration: Using a Library to Read Excel Files................................................... 2-25 2.3 Importing Data into SAS............................................................................................ 2-28 Demonstration: Importing a Comma-Delimited (CSV) File........................................... 2-31 Practice............................................................................................................... 2-35 2.4 Solutions................................................................................................................... 2-38 Solutions to Practices............................................................................................ 2-38 Solutions to Activities and Questions........................................................................ 2-39 2-2 Lesson 2 Accessing Data Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 2.1 Understanding SAS Data 2-3 2.1 Understanding SAS Data SAS Programming Process Analyze and Access Explore Prepare report on Export data data data results data 3 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Accessing data is the first step in the SAS programming process. There are many types of data files, and SAS makes it easy to access data and use it for reporting and analysis. Types of Data Structured data Unstructured data includes defined rows and columns many types able to be read by SAS SAS, Oracle, Teradata, Microsoft Excel, Hadoop, Versa tables, and others 4 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. SAS has engines to enable it to understand and read various types of structured data. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 2-4 Lesson 2 Accessing Data Types of Data Structured data Unstructured data includes data, but not defined columns must be imported into SAS text, delimited, JSON, weblogs, and other files 5 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Unstructured data must be imported into SAS before you can analyze or report on it. SAS makes importing data easy too. What Is a SAS Table? structured data.sas7bdat 6 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. A SAS table is a structured data file that has defined columns and rows. SAS tables have the file extension.sas7bdat. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 2.1 Understanding SAS Data 2-5 What Is a SAS Table? descriptor SAS table portion table name number of rows data date created portion column names column attributes data values 7 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. There are two parts to a SAS table: a descriptor portion and a data portion. The descriptor portion contains information about the attributes of the table, or metadata. The metadata includes general properties such as the table name, the number of rows, and the date and time that the table was created. The descriptor portion also includes the column definitions. The data portion of a SAS table contains the data values, stored in columns. SAS Terminology column or SAS table or data set variable row or observation 8 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 2-6 Lesson 2 Accessing Data Required Column Attributes for SAS Tables Name In SAS, all columns Type must have a name, type, and length. Length 9 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Required Column Attributes: Name 1 – 32 characters Name starts with a letter or underscore Type continues with letters, numbers, or underscores can be uppercase, Length lowercase, or mixed case 10 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Column names are stored in the case that you use when you create the column, and that is the way the column name appears in reports. After a column has been created, it can be typed in any case in your code without affecting the way that it is stored. Note: These same naming conventions should be followed for SAS table names. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 2.1 Understanding SAS Data 2-7 Depending on the environment used to submit your SAS code, SAS might allow for spaces and special symbols other than underscores in column and table names. If you use data sources other than SAS that have flexible column-name rules, SAS can make allowances for that. However, for simplicity and consistency, it is recommended to follow the standard SAS naming conventions. 2.01 Multiple Answer Question Which column names are valid? (Select all that apply.) a. month6 b. 6month c. month#6 d. month 6 e. month_6 f. Month6 11 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Required Column Attributes: Type Name Numeric Character digits 0 – 9 letters minus sign numbers Type decimal point special characters scientific notation (E) blanks 20568 -25.43 CA 555-1212 20568 Length 20E5 #Love this product! 13 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 2-8 Lesson 2 Accessing Data Required Column Attributes: Type Name Numeric SAS Dates Type 01Jan1959 01Jan1960 01Jan1961 -365 0 366 Storing dates as numbers makes Length calculations easy! 14 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. SAS date values represent the number of days between January 1, 1960, and a specified date. SAS can perform calculations on dates ranging from A.D. 1582 to A.D. 19,900. SAS time values represent the number of seconds since midnight of the current day. SAS datetime values represent the number of seconds between midnight on January 1, 1960, and an hour/minute/second within a specified date. Required Column Attributes: Length Name Numeric Character Type 8 bytes 1 - 32,767 bytes (~16 significant digits) (1 byte = one character) Length 15 C o p y r i g h t © S A S In s t i tu t e In c. A l l r i g h ts r e s e r ve d. Copyright © 2020, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. 2.1 Understanding SAS Data 2-9 The column length is the number of bytes allocated to store column values. The length is related to the column type. Numeric columns, by default, are always stored as 8 bytes, which is enough for about 16 significant digits. Character columns can be any length between 1 and 32,767 bytes, and a byte stores one character. A column such as Country Code that is always a two-letter code might be assigned a length of 2. A column such as Country Name that could have a varying number of characters must have a length at least as long as the longest country name. SAS uses floating-point representation to store numeric values. Floating-point representation supports a wide range of values (very large or very small numbers) with an adequate amount of numerical accuracy. For more information about how SAS stores numeric values, visit SAS 9.4 Language Reference: Concepts. 2.02 Activity 1. Navigate to the location of your course