Presentation is loading. Please wait.

Presentation is loading. Please wait.

SAS 101: The Beginner’s Guide to Beginning in SAS Frank DiIorio CodeCrafters, Inc. Chapel Hill NC.

Similar presentations


Presentation on theme: "SAS 101: The Beginner’s Guide to Beginning in SAS Frank DiIorio CodeCrafters, Inc. Chapel Hill NC."— Presentation transcript:

1 SAS 101: The Beginner’s Guide to Beginning in SAS Frank DiIorio CodeCrafters, Inc. Chapel Hill NC

2 Off-Topic: Staten Island and Hilton Head: Separated at Birth???

3 Today We'll Discuss Company background Overview of the product, focusing on components of Base SAS Sample programs Resources for learning more about the product line It's a quick overview. Don't get wrapped up in syntax and details.

4 Some Background (1 of 2) Started at NC State University in late 60's Initial focus was data manipulation and statistics on IBM mainframe (System 360/370) Incorporated in July 1976 Breadth of the product and its user base grows – graphics, econometrics packages, followed by "vertical" products Continued expansion in functionality, platforms, data interchange

5 Some Background (2 of 2) Currently, nearly $2 billion in revenues, high customer (43,000+) and employee (10,000) retention rates, 400+ offices worldwide, and nationally known as a good employer. Largest privately-held software company in the world. Co-founder and President Jim Goodnight is wealthiest man in North Carolina. Regarded by users as a company that is highly responsive to its customer base. Over the years, the idea of being a professional SAS programmer (not, for example, "a utility rate anlayst who uses SAS") has "gained traction."

6 The Big Picture, Take 1: SAS Viewed As an Elephant Recall the blind Indians touching an elephant, each touching a different part and thinking it was a tree, a spear, a fan, etc. If SAS were an elephant, here's what it might look like:

7 The Big Picture, Take 2: Platforms, Products, Solutions Powerful, user-friendly, and cutting-edge. But … predefined functionality. Consider what's at the heart of it all (next slide)

8 global statements (options, headers, footers, etc.) The Big Picture, Take 3: Focus on Base SAS Base SAS is at the heart of it all Here it is, in a vastly simplified nutshell, illustrating key concepts of data manipulation, DATA step-PROC interplay, and pervasive influence of the macro language and global statements that influence the SAS program's execution environment. macro DATA step PROCsODS doc. pdf. rtf. txt. xml. others data. sas. oracle. access. excel. others

9 What’s Most Important? It varies by your needs, of course, but it’s always important to understand how the core elements work Knowledge of Base SAS is essential. Using it, you can: oRead and write data in virtually any format (e.g., SAS, Microsoft Access/Excel, Oracle) oManipulate data using SAS's syntax and/or industry- standard Structured Query Language (SQL) oWrite summarized or detailed graphic or text-based reports in many different formats (JPG, GIF, HTML, plain text, PDF, RTF, etc.) oBetter understand and effectively use the other components of the SAS System

10 Base SAS Basics What does a SAS progam look like? oA series of statements, delimited by a semicolon oEach statement performs a specific activity: calculation, rearranging or printing a dataset, etc. oSAS knows if the statement is syntactically (not logically) correct by determining its location in the program (its context) and applying syntax rules. Principal program units/building blocks: oDATA step ("third generation") oPROCEDUREs, or PROCs ("4 th generation") oOutput rendering (aka Output Delivery System, ODS) oText generation (Macro language) How to run a program? oBatch oInteractive oEither way, the syntax is (nearly) identical

11 A Base SAS Procedure Sampler contentsDisplays dataset attributes printQuick listing of observations in a dataset reportDisplay observations in a dataset, with possibility of a high degree of output formatting. tabulateSummarize and display data, grouped by one or more classification variables datasetsPerform dataset management tasks such as copying, renaming, modifying attributes freq, means Simple univariate statistics such as mean, sum, frequency distribution. sqlManipulate SAS and other datasets using Structured Query Language formatCreate customized tools to control the reading and display of variables sortRearrange the order of observations in a dataset. Data handling is at the heart of it all. Now let's look at datasets.

12 Dataset Basics Much of the program's activity is focused on manipulation of datasets. Datasets are collections of measurements on subjects oThe items being measured are variables oA collection of items for an event is an observation Other products sometimes use the terms columns and rows Datasets can be read and written in SAS's "native" format or as spreadsheets, tables in a database, etc.

13 It Isn't Just a Single Language SAS software addresses a wide range of user needs. This diversity is reflected in the variety of syntax. Different sub-languages, all working together despite disparate appearance and "look and feel" Among these are: Base SAS SQL (Structured Query Language) IML (Interactive Matrix Language) Macro We'll focus on Base SAS and macro.

14 Statement Syntax Most statements have identifiers, keywords, values, ending with a semicolon: libname master 'p:\archive\data'; data test; set master.fy2005; change = (rev2005-rev2004) / rev2004; run; proc print data=test; title "FY2005, with CHANGE variable added"; run; Consider: Case usually doesn’t matter (unless it's enclosed in quotes, as in the TITLE statement, above) Spaces usually don’t matter Order of statements does matter If you don't completely specify a statement, SAS assigns (usually) smart preset, default values.

15 Sample Program libname anldata 'f:\dev\c1\data\analysis'; data aeSer; set anldata.ae; aeDur = (aeEnd – aeStart) + 1; if aeSev >= 2 then output; run; proc sort data=aeSer; by aeSev; run; proc print data=aeSer; by aeSev; title "Mild or Severe Adverse Events"; run; Identify the data source [1], then read a dataset [2], create a new variable [3], and write only observations meeting a particular criteria to a new dataset [4]. Rearrange the order of observations [5], then list the dataset [6]

16 Sample Program (sidebar) libname anldata 'f:\dev\c1\data\analysis'; data aeSer; set anldata.ae; aeDur = (aeEnd – aeStart) + 1; if aeSev >= 2 then output; run; proc sort data=aeSer;by aeSev;run; proc print data=aeSer; by aeSev; title "Mild or Severe Adverse Events"; run; SAS doesn't impose many rules. The following is functionally equivalent to the previous slide, but is harder to read due to lack of indentation and line breaks. Take the time to make even simple programs readable!

17 Modify the Sample Program 1.Use options to control display of date and page number 2.Use Output Delivery System (ODS) to create PDF libname anldata 'f:\dev\c1\data\analysis'; options nodate number; data aeSer; set anldata.ae; aeDur = (aeEnd – aeStart) + 1; if aeSev >= 2 then output; run; proc sort data=aeSer; by aeSev; run; ods listing close; ods pdf file='AEser.pdf'; options noDate noNumber; proc print data=aeSer; by aeSev; title "Mild or Severe Adverse Events"; run; ods pdf close; ods listing; 1 2 2

18 What Have We Learned So Far? SAS syntax is compact and flexible It pays to make it readable DATA step lets you read, write and manipulate data from many sources. PROCs do this as well, and perform common reporting and analytical tasks with a minimum of syntax. SAS software really shines when you need to exploit repetition. Let's look at the macro language.

19 Macro Language (1 of 5) Suppose our datasets had a variable PTID that held the subject number and that we wanted to print only for a specific subject. One approach is shown below. libname anldata 'f:\dev\c1\data\analysis'; ods listing close; ods pdf file="ptList.pdf"; proc print data=anlData.DM; where ptid = '001022'; title "Demography for "; run; proc print data=anlData.AE; where ptid = '001022'; title "Adverse Events for "; run; proc print data=anlData.CM; where ptid = '001022'; title "Con Meds for "; run; ods pdf close; ods listing; Specify "filter" value in both WHERE and TITLE statements Duplicate the filter value in other calls to PRINT procedure

20 Macro Language (2 of 5) Consider the tedium involved when you'd want to print data for two subjects. You'd have to duplicate the statements for the next subject, as shown below: proc print data=anlData.DM; where ptid = '001022'; title "Demography for "; run; proc print data=anlData.AE; where ptid = '001022'; title "Adverse Events for "; run; proc print data=anlData.CM; where ptid = '001022'; title "Con Meds for "; run; PRINTs for first PTID value proc print data=anlData.DM; where ptid = '001145'; title "Demography for "; run; proc print data=anlData.AE; where ptid = '001145'; title "Adverse Events for "; run; proc print data=anlData.CM; where ptid = '001145'; title "Con Meds for "; run; PRINTs for second PTID value

21 Macro Language (3 of 5) libname anldata 'f:\dev\c1\data\analysis'; ods listing close; ods pdf file="ptList.pdf"; %macro listPT(id=); proc print data=anlData.DM; where ptid = "&id."; title "Demography for &id."; run; proc print data=anlData.AE; where ptid = "&id."; title "Adverse Events for &id."; run; proc print data=anlData.CM; where ptid = "&id."; title "Con Meds for &id."; run; %mend; %listPT(id=001022) %listPT(id=001145) ods pdf close; ods listing; 1.We create a macro – %listPT – with the ability to accept an ID value (the ID= portion of the %macro statement) 2.Then we run, or "call" the macro twice, once for each patient. Basically the same program as before, but no patient ID values, just references to them. ID is a macro parameter 1 2

22 Macro Language (4 of 5) libname anldata 'f:\dev\c1\data\analysis'; ods listing close; ods pdf file="ptList.pdf"; proc print data=anlData.DM; where ptid = "001022"; title "Demography for "; run; proc print data=anlData.AE; where ptid = "001022"; title "Adverse Events for "; run; proc print data=anlData.CM; where ptid = "001022"; title "Con Meds for "; run; proc print data=anlData.DM; where ptid = "001145"; title "Demography for "; run; proc print data=anlData.AE; where ptid = "001145"; title "Adverse Events for "; run; proc print data=anlData.CM; where ptid = "001145"; title "Con Meds for "; run; ods pdf close; ods listing; The macro language processor generates, then runs, statements. The previous slide showed the program. What SAS actually processed was: PRINTs for first PTID value PRINTs for second PTID value

23 Macro Language (5 of 5) This simple example used the macro language for simple text substitution. More sophisticated applications allow you to: Write part of, all of, or several statements based on a logical condition. Write "bulletproofed" applications that identify and react to incorrect or suspect user parameters, data values, etc. Control output formatting, based on user- specified parameters Create datasets Create "global" macro variables that can be used by other macros and applications.

24 Resources You're using one right now: user groups Review program presentations' keywords, interest level. Also: visit Demo Room, talk to poster presenters (today 1:30-2:30) oSee support.sas.com\userGroups for details about other regional, local, and national groups Web sites ( support.sas.com, ) SAS Online Help Publications (by SAS Institute; Books By Users; others) Visit the Publications booth in the Demo room Colleagues oSAS-L list server via: Google Groups ( sys.sas/topics?hl=en ) UGA ( ) oat work (people, sample programs)

25 Recap Many products underneath the SAS System "umbrella" Base SAS is, arguably, the most versatile, and has a strong presence in the job market Building blocks: DATA step, PROCs, ODS, macro Vast power, vast potential for confusion, so take advantage of resources here, on Web, elsewhere.

26 Contact Thanks for attending!


Download ppt "SAS 101: The Beginner’s Guide to Beginning in SAS Frank DiIorio CodeCrafters, Inc. Chapel Hill NC."

Similar presentations


Ads by Google