
Introduction
Develop a foundational understanding of the essential components of SAS programming, the underlying processes behind why tasks operate, and apply biology-inspired strategies for efficient learning of procedures.
This lecture provides you with an outline of the course; a lay out of the notions that will be covered in this course. It should help you decide which parts/notions are more appropriate for you. From the Course Materials, the file: Codes_for_Building_Course_Source_datasets contains all the codes to build the data sets needed throughout this course. Run this code in order to create the needed data sets. Create library and declare it at each DATA STEP/DATALINES code to save the created data sets in a permanent location
What you need to start coding
Overview of all of the elements that make up SAS programming language:
- DATA STEP
- PROC STEP
- PROC SQL
- MACROS
- GLOBAL statements and OPTIONS
- IML and SCL (won't be covered in course)
Overview of the main tasks accomplished with DATA STEP:
Data manipulation including:
- Reading, filtering, merging, concatenating, exporting
- Data transformation: variables creation, recoding...
Overview of of the USE of PROC STEPS (Procedures):
- Reporting
- Analyses
- Graphics
- Data transformation
- Utility procedures
Overview of PROC SQL use:
- Manipulating data
- Producing reports
- Designed for relational database systems
Overview of the use of MACROS:
- avoid repetition in coding
- Make code more generic
- expand SAS elements capabilities
- Make logical decisions based on content of data
Simplest ways for creating a DATA STEP:
- the output statement for creating output DATA SET
- the RUN statement for instructing SAS to complete processing for each record
- Saving output data sets in a permanent location
- The use of libraries associated to permanent folders
Ways for reading input data sets in:
- Using: SET, MERGE, INFILE & INPUT, or INPUT & DATALINES
Navigating between DATA STEP and PROC STEPS for keeping track of data manipulation
- Describe variables: LABEL statement
- Describe values: FORMAT statement
How do we select data columns of interest:
- KEEP= and DROP= options
- KEEP and DROP statements
How do we filter data:
- Filter on the way in: WHERE STATEMENT
- Filter on the way out: IF CONDITION
Combining data by a common (set of) column(s): Merging
- The need to sort, index, or use NOTSORTED for merging
- Explore ONE TO ONE, ONE TO MANY, and MANY TO MANY merges
- Explore INNER JOIN, LEFT JOIN, FULL OUTER JOIN
Combining data sets of similar columns by stacking: CONCATENATE
- Using one SET for all declared data sets
- Using one SET per declared data set
Use of variable assignment statement for creating and modifying variables
- Data types in SAS
- Setting length for character variables
Summarizing data:
- Use of addition and subtraction
- how missing values are treated
Using functions:
- Dates functions
Summarizing data:
- Use of summary functions as alternative to addition and substraction
Use of functions: SUBSTR and SCAN
Practice data transformation by extracting emails with substring and scan, using delimiters, index, and find to adapt to fixed and not fixed positions.
Use of functions: Concatenation functions
Use of functions: Remove space
Use of functions: conversion functions: INPUT and PUT
Use of conditional statements:
- IF THEN
- IF THEN DO
Learn the SAS data step and proc step, counting statements by semicolons. Create and transform datasets using set, merge, input, and assignment statements, with filters, formats, and library management.
PROC PRINT, PROC FREQ, and PROC MEANS for:
- Reviewing and cleaning up data
- Producing descriptive statistics and reports
Learn to subset by columns for print, freq, and means, limiting visible variables to avoid oversized outputs, and distinguish handling of categorical versus numeric variables with appropriate keywords and prefixes.
Learn how to subset rows in SAS using where conditions and the obs option, then print the top five older records by age, after sorting and combining obs.
Explore features unique to proc print, including using labels and identifiers, and generating category summaries and sums in a sorted report.
Describe using proc freq to generate two- and three-dimensional cross-tabulations with counts, percent, and expected values; subset with where, handle missing data, and tailor tables by dropping unwanted percent columns.
Learn to apply proc print-freq-means to proc means by using the class statement to break down statistics by a categorical variable, including mean, median, standard deviation, min, max.
Outputting STATISTICS to data sets
- Chi square for assessing the association between categorical variables
Calculating crude associations:
- Odd ratio (OR)
- Relative risk (RR)
PROC TABULATE is a combination of PROC FREQ and PROC MEANS
- A PURE PROC FREQ
- A PURE PROC MEANS
- Or a combination of PROC FREQ and PROC MEANS
Compare proc tabulate as a pure proc means with proc means, control decimals via maxdec, and use class statements to segment education and marital status.
Learn to use proc tabulate to combine multi-dimensional statistics with tabulations across age, income, and gender, generating separate tables for each category.
Utility PROCEDURE: PROC CONTENTS
- learn about variables
- organize variables
Using PROC FORMAT to create user defined formats:
- using VALUE STATEMENT
- using CNTLIN=option
Manage SAS formats by storing them in the work library or permanently in a named library using proc format, libname, and proc catalog.
Overview of REGRESSION
- PROC REG
- PROC GLM
Learn how to handle categorical variables in regression by creating dummy variables with a reference category, then interpret coefficients for education levels and compare groups.
Learn to run a regression in SAS with PROC GLM, handle categorical variables, set a reference category, and interpret parameter estimates and type II sums of squares.
Explore sum of squares in regression, comparing sequential and type iii sums of squares and how variable order affects significance, interpretation, and main effects limitations.
Transposing data using PROC TRANSPOSE
Explore SAS procedures, classify everyday, utility, report-building, statistical analysis, and import/export tasks, and learn to reuse one-time reports as templates for future analyses.
Explore SAS PROC SQL and its relational database capabilities, focusing on the select statement to retrieve data, filter with where, sort with order by, and create new datasets using DML.
Explore proc sql's basic select form, including from clause, labels and format options, comma-separated columns or star, and saving results with create table.
Remove duplicates in SAS PROC SQL using distinct or group by, and learn when summary functions (min, max, sum, mean, median) are needed to produce correct outputs.
Learn how proc sql summary functions handle missing values, count records across groups, and apply nonmissing counts, breaking down by marital status and gender.
Explore filtering data with PROC SQL using where and having conditions, handle missing values, and apply operators, between, in, and wildcards, plus post-aggregation filtering by median age.
Explore how proc sql implements inner, left, and full joins to combine datasets, handle missing matches, and qualify column references by table name to avoid ambiguity.
Explore how subqueries power SAS PROC SQL by filtering with where and having, adding computed columns, and deriving first visit dates, minimum dates, and education frequencies across subjects.
Explore how proc sql set operators such as union, union all, intersect, and except manipulate data from two datasets A and B, showing how duplicates are removed or kept.
Discover how SAS macros work, including the four main creation methods, to reduce repetitive code and support complex logic, with automatic variables and functions.
Learn how to define and use global macro variables with the %let statement, including naming rules, value capture, and referencing with ampersands.
Explore how SAS macros encapsulate reusable code with %macro...%mend, using global and local macro variables, and define positional and keyword parameters to enable conditional execution across datasets.
Learn to concatenate macro variables with static characters to form names by year, using ampersands to denote macro variables and dots when needed.
Explore SAS macros with conditional statements and loops, including if, if-then, and percent if, and learn how to apply them inside and outside macros to create categories and automate processes.
Learn how to define and use SAS macros with call symput, capture dataset values at different processing stages, and apply conditional logic to derive education and gender counts for reporting.
Discover how double scan captures dataset variable names, types, and lengths and creates per-variable macros. Use the descriptives macro to loop, convert, and summarize.
Learn how to use PROC SQL's SELECT INTO to create macro variables from query results, handling single or multiple rows, and using a delimiter to join values.
Learn to debug macro code using percent, explore macro environment with global and local variables, and apply macro and system functions like scan and substr to manipulate values.
Learn macro quoting in SAS, including how to protect symbols and characters from interpretation. Discover how ampersand and percent signs relate to macro variables and execution time.
Examine the characteristics of SAS steps, focusing on data steps and procs, and compare global statements, options, and how steps manipulate data.
Read assets, assemble a demographic baseline with HDL and LDL tests, and prepare a reporting dataset. Create temporary copies, clean data, and implement checks.
Explore how to manage data changes within SAS code, track modifications in the source data, and build baseline HDL and LDL using subqueries, merges, and temporary datasets for quality checks.
Explore global statements and the libname option to manage libraries, including temporary versus permanent libraries, engines, and how file names and paths determine data access and storage, an Excel dataset.
Explore how global ODS statements control SAS report destinations such as PDF, Word, and Excel, set output file names and paths, and customize styles for publication-ready results.
Explore SAS global titles and footnotes, using up to ten ranked levels to create titles and subtitles, with rules for overriding and canceling as ranks rise.
Understand global options and default settings that manage SAS environments, and learn to adapt by changing dataset display limits, naming rules, and page size and page numbers.
This lecture ties SAS programming elements together, highlighting data step, proc step, macro usage, and global statements and options, plus the semicolon based statement structure for data analysis and reporting.
Explore SAS metadata and data step fundamentals, focusing on input, output, and the body, library handling, and using contents to inspect variables and formats.
Learn to craft the SAS data step output statement and input statement, manage libraries and datasets, including temporary and permanent ones, and apply conditional routing, duplication, and external file output.
Manage input statements in SAS by renaming variables, deciding which data to drop from input versus output, and handling delimiters, merges, and external data sources.
Explore the body of a data step and how to use select when to map occupations to categories, compare it with if then, and create bmi categories with when conditions.
Learn to compute running totals in a SAS data step using sum and cumulative sum, retain values across records, and calculate total income by occupation category.
Explore how the SAS data step uses do loop, do until and while constructs to accumulate balance, compute interest over years, and control loop termination.
Learn how to use arrays in SAS to avoid repeating the same fahrenheit-to-celsius conversion across multiple columns, applying one formula to a six-column range from Monday to Saturday.
Explore SAS arrays to transpose data, turning columns into rows (and vice versa) while preserving values, with examples on temperature conversion to Celsius and student test data.
Explore using arrays to transpose temperature data across multiple rows and columns. Build input and output steps with temporary arrays to transpose by month, capturing columns and days.
Access data from diverse sources—text files, Excel, SPSS, Oracle—and read it into SAS, while managing libraries, using temporary copies, and merging or sorting datasets.
Explore reading external data in SAS using infile and input, comparing delimited text and formatted input, and managing delimiters, spaces, and field lengths.
Learn to read Excel files using the Excel engine and the library New Underscore Lane, explore reading data, handling column names, and applying conditions such as the Walsingham condition.
Connect to the database using a server or A.B.C. connections, specify a library name and credentials, and set perceptual options to access tables before selecting columns and disconnecting.
Explore how to use proc import in SAS to load delimited text and Excel files, set paths, replace outputs, and manage getnames and dbms options.
In designing this course, we tried to incorporate the current state of affairs ( in the INTERNET AGE) when it comes to learning a programming language, where the sheer amount of resources
at our disposal can be both a curse and a blessing. This is no less true for SAS programming. There are more than enough resources for anyone embarking on the goal of learning or upgrading their skills in SAS to rely on: (1) SAS particularly extensive documentation about all of their products, (2) the dynamically active community of programmers and users and their contributions; (3) the no less important arrays of courses (paid or not) offered, (4) and even the ability to learn from people next to us. We believe that none of these options is either the definitive solution, nor worthless.
However, for a learner, especially those with no prior knowledge about the programming, making the right choices can be both stressful and/or costly.
So we designed this course in a way to allow you to see the forest from steps/far away or from above so to help you build a contextual self-awareness before you step into it. Once, you have a sense of how your achievement will look like when you get there, we are convinced that (1) the journey will be less stressful, (2) any prior investment you have made or any investment you will make on that front will add value to this one. If you follow through our offer and give it a real try, many of the resources, you have found confusing before will likely start to sound valuable for you. In order to balance the need to help you get a complete picture of SAS programming and not make your journey endless, we put a serious emphasis on the WHY: why SAS does something the way it does; we go to the essential elements of each SAS component, so that you learn more than just the mechanics of making it work when you need it.
For example, in preparing the lesson about MACROS, we made sure to answer the following questions, among other things:
- Why do we need macros?
- how do we create macros (the different methods)
- why do we need different methods to create macros? how do the different methods compare?
- and when it comes to these tools, we let you know upfront that there are limitations (don't even know why we find the need to repeat this to you--- everybody knows that there is no such thing as a perfect/bugs free tool when it comes to POGRAMMING). So expect errors and work to fix them; any error you manage to fix yourself is one more stair on your stairways to professional experience. Don't be afraid of carefully reading your log, then your code again before you throw the towel; the most elementary errors (simple syntax errors, typos...) are the ones that will stick with you the longest in your journey. We highlighted some of those limitations (ex.: macro quoting).
At a high level, here is what we cover:
Part I: SAS Programming components
Lesson 1: DATA STEP
Lesson 2: PROC STEPS
Lesson 3: PROC SQL
Lesson 4: MACROS
Part II: SAS Programming Structure
Lesson 1: STEPS and STATEMENTS
Lesson 2: More on DATA STEP
Part III: Reading data into SAS
Lesson 1: Reading from various sources
Lesson 2: Reading using INPUT STYLES (raw data)
Part IV: SAS Program Data Vector (PDV)
Lesson: PDV
As you can see, we cover most SAS components/programming elements. For each lesson, we start with a few basic notions and expand in level of difficulty throughout the lesson.
Whether you intend to prepare SAS based certification (without going through the usual painful memorization exercise) or list this language on your resume, we are convinced that this course will helps you achieve your goals. A lot of practice exercises were included; they are targeted mostly at people who are acquiring this course with certification (base SAS) in mind.