𝗦𝗔𝗦 𝗧𝗿𝗮𝗶𝗻𝗶𝗻𝗴 𝗢𝗻𝗹𝗶𝗻𝗲 𝟮𝟬𝟭𝟵 "𝗦𝗔𝗦 𝗣𝗿𝗼𝗴𝗿𝗮𝗺𝗺𝗶𝗻𝗴 𝟭– 𝗘𝘀𝘀𝗲𝗻𝘁𝗶𝗮𝗹𝘀" - 𝗙𝗿𝗲𝗲 𝗢𝗻𝗹𝗶𝗻𝗲 𝗖𝗼𝘂𝗿𝘀𝗲


Learn SAS programming in 2019 (Free eLearning Course Available)

So why SAS?

We all know that time is money, so it would be wise to question why to begin learning SAS before even spending any time to consider. In this increasingly data-driven world, SASthe statistical analysis system—is an excellent place for data-focused individuals to begin delving into the world of programming. Despite the fact that SAS has been around in one form or another since the 1970s, it is still a highly trusted and valuable solution, well liked and respected by many institutions for its robust scripting and analysis capabilities. Additionally, the simplicity of it's design and interface, keeps the application relatively lightweight, considering the number and scope of actions your programs may be executing simultaneously. In the same vein, SAS skills are prized due to the flexibility of software as a platform. One program can pull data from various data sources, including databases, Microsoft Office files, or even external network sources, and after processing the data and generating values for any custom variables you have defined, the SAS data set can be presented in shared in a wide variety of reporting formats, including web formats that you can push directly to your favorite cutting-edge web applications for additional processing or present ion steps. The beauty of SAS is that it really can 'do anything', as they say, in terms of organizational data management and analysis,  if the programmer has the right level of skills and know-how.

So, the purposes of this blog post is still to help me keep track of significant notes as I work through the free training that I recently discovered SAS offers on their website.

They also offer coursework in formats that are not free. You can review locations and times for in person training sessions, as well as live video training on this page.

For my part, the free e-Learning format, which consists of videos, as well as interactive practice exercises and quizzes, was the clear choice.

You will need to install SAS software to completed the exercises appropriately. Fortunately, the training provides setup steps that are specific to version of SAS you have installed, including the free university edition. I will do by best to keep my notes in an a clear and organized format as I work through the training in case you are interested in learning more.

Part of the reason I've decided to share these notes in a blog post is that for years I've been discouraged from actually learning to code SAS programs because their website never seemed to make it clear on where to start. It seems a bit overwhelming at first. so this post is actually meant to serve as both a reference and a jumping-off point for any others like myself who do not have a particularly technical educational background; however, some basic programming experience and data analysis skills would be helpful.

Step One: Get a user account at the SAS website

For the free online e-learning version of the training, start here: http://support.sas.com/training/options/#s1=3

[Instructor lead courses are also available for a fee]

Use an email address and create a password to create a user account to sign in.

Once you have a user name and password, you can begin logging by using the following URL to to access the traing modules: https://support.sas.com/edu/schedules.html?ctry=us&crs=PROG1
Note: You will will only have 180 days to complete the training one you have registered for this course. Even though you might be be able to register for a new account with a seperate email address after your time has expired,  the estimated time needed to complete the course is 24 hours, so I assume they did this as favor to help keep you on track. 

 SAS Programming 1: Essentials (Free Online Training)

This course is for users who want to learn how to write SAS programs. It is the entry point to learning SAS programming and is a prerequisite to many other SAS courses. If you do not plan to write SAS programs and you prefer a point-and-click interface, you should attend the SAS Enterprise Guide 1: Querying and Reporting course.

This course can help prepare you for the following certification exam(s): SAS Base Programming for SAS 9SAS Certified Clinical Trials Programmer Using SAS 9.

Learn how to:

  • navigate the SAS windowing environment
  • navigate the SAS Enterprise Guide programming environment
  • read various types of data into SAS data sets
  • create SAS variables and subset data
  • combine SAS data sets
  • create and enhance listing and summary reports
  • Validate SAS data sets.

Who should attend:

Anyone starting to write SAS programs. 

Course Overview (URL Shortcuts)

Hyperlink shortcuts are included below. 
Note: You will need to be registered and logged in to your account on the SAS training website in order for these links to navigate to the training module successfully. 

Lessons

Course Overview

Before you can begin using SAS to access this example data, you will need to do a bit of setup work to configure the connection. Depending on the version of SAS that you are using, the steps might differ slightly. Fortunately, the instructions provide instructions that are tailored to the version of SAS that you have installed. 

Follow the link to this page to be directed to the appropriate setup file instuctions, based on your version of SAS. (https://vle.sas.com/pluginfile.php/30233/mod_scorm/content/8/eclibjr/setup_win.htm)

Lesson 1: Getting Started with SAS Programming

Overview: 

You will become familiar with the high level steps involved in the SAS development process.

Highlights:

  • Almost statements in SAS are Proc Statements or Data statements (also referred to as "proc steps" and "data steps")
  • "Global statements"  fall outside of Proc steps and Data steps. 
  • White space does not affect output. 
  • All statements must end with semicolon

Summary Text:

SAS is a suite of business solutions and technologies to help organizations solve business problems. Base SAS is the centerpiece of all SAS software.

It can be useful to look at SAS capabilities in a simple framework:
  • Access data: Using SAS, you can read any kind of data.
  • Manage data: SAS gives you excellent data management capabilities
  • Analyze data: For statistical analysis, SAS is the gold standard.
  • Present data: You can use SAS to present your data meaningfully.

Understanding the SAS Programming Process

 Here is the overall process of programming in SAS
  1. Define the business need.
  2. Write a SAS program based on the desired output, the necessary input, and the required processing.
  3. Run the program.
  4. Review your results.
  5. If you find inaccuracies or errors, you debug or modify the program.
Depending on your results, you might need to repeat some of the steps.

The power of SAS is that you can use it to read any type of data, including the following three major file types
  • Raw data files contain data that has not been processed by any other computer program. They are text files that contain one record per line, and the record typically contains multiple fields. Raw data files aren’t reports; they are unformatted text.
  • SAS data sets are specific to SAS. A SAS data set is data in a form that SAS can understand. Like raw data files, SAS data sets contain data. But in SAS data sets, the data is created only by SAS and can be read only by SAS.
  • SAS program files contain SAS programming code. These instructions tell SAS how to process your data and what output to create. You can save and reuse SAS program files.

Lesson 2: Working with SAS Programs

Overview:

This lesson includes the first activity that asks that you input some code into the SAS program running on your machine. 

The course begins by requesting that you define the Orion Library (Orion Star is the fictitious company referenced in example problems throughout the training.)

Highlights:

Mismatched quotations, missing semicolons and misspelled commands are the most common types explanations for errors in SAS code.

Summary Text:



This summary contains topic summaries, syntax, and sample programs..

Exploring SAS Programs

A SAS program consists of DATA steps and PROC steps. A SAS programming step is comprised of a sequence of statements. Every step has a beginning and ending step boundary. SAS compiles and executes each step independently, based on the step boundaries.
A SAS program can also contain global statements, which are outside DATA and PROC steps, and typically affect the SAS session. A TITLE statement is a global statement. After it is defined, a title is displayed on every report, unless the title is cleared or canceled.
SAS statements usually begin with an identifying keyword, and always end with a semicolon. SAS statements are free format and can begin and end in any column. A single statement can span multiple lines, and there can be more than one statement per line. Unquoted values can be lowercase, uppercase, or mixed case. This flexibility can result in programs that are difficult to read.
Conventional formatting, also called structured formatting, uses consistent spacing to make a SAS program easy to read. To follow best practices, begin each statement on a new line, indent statements within each step, and indent subsequent lines in a multi-line statement.
Comments are used to document a program and to mark SAS code as non-executing text. There are two types of comments: block comments and comment statements.


/* comment */
* comment statement;

Diagnosing and Correcting Syntax Errors

Syntax errors occur when program statements do not conform to the rules of the SAS language. Common syntax errors include misspelled keywords, missing semicolons, and invalid options. SAS finds syntax errors during the compilation phase, before it executes the program. When SAS encounters a syntax error, it writes the following to the log: the word ERROR or WARNING, the location of the error, and an explanation of the error. You should always check the log, even if the program produces output.

Mismatched or unbalanced quotation marks are considered a syntax error. In some programming environments, this results in a simple error message. In other environments, it is more difficult to identify this type of error.

Sample Programs





Submitting a SAS Program


data work.newsalesemps;
set orion.sales;
where Country='AU';
run;

title 'New Sales Employees';

proc print data=work.newsalesemps;
run;

proc means data=work.newsalesemps;
class Job_Title;
var Salary;
run;

title;

Adding Comments to Your SAS Programs






*This program uses the data set orion.sales to create work.newsalesemps.;
data work.newsalesemps;
   set orion.sales;
   where Country='US';
run;

 /*
proc print data=work.newsalesemps;
run;*/
proc means data=work.newsalesemps;
   class Gender;
   var Salary/*numeric variable*/;
run;

Viewing and Correcting Syntax Errors






daat work.newsalesemps;
 length First_Name $ 12 
     Last_Name $ 18 Job_Title $ 25; 
 infile "&path/newemps.csv" dlm=',';
 input First_Name $ Last_Name $ 
 Job_Title $ Salary; 
run;
proc print data=work.newsalesemps 
run;

proc means data=work.newsalesemps average max; 
 class Job_Title;
 var Salary; 
run;


For your Convenience: Lesson 2 Quiz Solutions




Saved Links: