Learning SAS (University; LinkedIn; 9.4; Certification) – Part 01

Over the years, I’ve wanted to learn SAS. While at USC, I heard about SAS University, which originally required downloading software onto something like a Virtual Machine (I used VirtualBox). Recently, everything has shifted to online, which makes life easier.

LinkedIn Learning (formerly Lynda.com) has a bunch of intro to SAS Programming courses towards a Basic Programming certification (SAS 9.4 Certification)

I’ll be creating blog posts for each of the lessons. The basic steps I’ll be following are: Access Data; Explore Data; Prepare Data; Analyze and Report on Data; Export results.

My immediate thought is that SAS will be useful for analyzing data that I’m researching regarding women in aviation. There are a series of datasets from the FAA.

SAS Programming Interfaces

SAS Studio
-This is a web-based interface between end-user and SAS
-Basics needed for programming (editor; messages – log; review output, reports, etc)

Browsing data within SAS Studio
-Libraries (on left pane)
-My Libraries (click on the twistie)
-SASHelp (various Sample SAS tables)
-CLASS Table – This opens, on the right, a bunch of columns and rows of students (age, height, etc)
Note: It’s easy to select/deselect columns, and also move the column selector to the left for more space.
-To recreate “Program 1” – 7 blips icon (New Options), New SAS Program (F4)

-Initial sample code – reads sashelp.class and enters into myclass
data myclass;
TAB set sashelp.class;

proc print data=myclass; — prints the myclass table

After running, I have my table (columns, fields). I also have ability to look at: code; log; results; output data. Code is the program I just entered. Log gives a summary of what happened, including total CPU time used, etc and “Errors, Warnings and Notes”. Results is the table that was outputted. Output Data is what I originally had when I opened the sashelp.class table.

Size grid columns to content. This is a way of minimizing the field width, so you see more data on the screen. In Output data, either right click and select that, or you can set in preferences.

To run specific parts of the code:
-Select the lines you want

Have “Results” off to the side:
Drag Results to the right until the little icon turns green. It’s also obvious when it shades a block on the right. You can reverse by dragging results back to the where you started from.

SAS Syntax
-SAS Program is a sequence of steps
-DATA step or PROC (Procedure) steps
-The step will begin with either data or proc
-The steps will typically end with a “run;” statement
-In general, a data step reads data from input source; processes it; and creates a SAS table
-A data step may also filter, compute new columns, join tables, etc
-A proc step can generate reports, graphs, compute stat and analysis.
-All statements must end with a ;
-Some statements only have key words within the step, but may have something that are assignment statements
-Global Statements — outside of data and proc steps. Typically define option or settings for SAS session. Global statements do not need a run; statement after them

-Comments: For multiple lines of a comment — begin with /* and end with */
-Comments: To comment out a single line, lead with a “*”
-Comments: One way of creating a comment is: write the comment; select it; press “Command, /”

-Formatting the code: Ideally you have a blank line between steps. Also, use tabs to indent stuff. If you haven’t done this, there is a handy button called “Format code” that will do it for you. In the editor, the comment is in a green color

-Syntax Errors – finding and resolving: These are just a fact of life in programming. Misspelled keywords, unmatched quotation marks, invalid options, missing semicolons. SAS enters warning or error in log.
-Suggestion: Always look at the Log after running, and review from top to bottom. Look for obvious errors, including just before the highlighted line.

About Paul

CERT Coordinator, Ham Radio Operator, GTD Fan; Photographer; Domino/Notes Administrator
This entry was posted in Programming, SAS. Bookmark the permalink.