340 likes | 714 Views
SAS Statistics with SAS package. PGDASS class. SAS. SAS: Statistical Analysis System 9.2 Statistical Package: very costly Pronounced as SAAS. Change date to April 2014 Right click on date Adjust date and time Change date to April 2014. What is SAS?.
E N D
SASStatistics with SAS package PGDASS class Anil Arekar
SAS SAS: Statistical Analysis System 9.2 Statistical Package: very costly Pronounced as SAAS Anil Arekar
Change date to April 2014 • Right click on date • Adjust date and time • Change date to April 2014 Anil Arekar
What is SAS? • Began as a statistical package • Also allows users to: • Store data • Manipulate data • Create reports • PDF • Excel • HTML • XML • RTF / Word • Etc. Etc. Etc.
What is SAS? • Also allows users to: • Create graphs • Create maps • Send e-mails • Create web applications • Create iPhone Apps • Access R • Schedule regularly run reports • Etc. Etc. Etc.
Log: Details about jobs you’ve run, including error messages Explorer Window: See libraries and SAS datasets Enhanced Editor: Where you write your SAS code
Results tab: List of previously run results Output Window: Basic view of results and output (Also known as “Listing Destination”)
Run: Submits your SAS code (“The Running Man”)
You can submit the program as a whole or Run only a portion of highlighted code
Chunks of code will be processed in the order you RUN them, not necessarily in the order you wrote them
DATA steps: Read and write data, manipulate data, perform calculations, etc. Every DATA step creates a new dataset
Every SAS program can have multiple DATA and PROC steps PROC steps: Produce reports, summarize data, sort data, create formats, generate graphs, etc. etc. etc.
Global statements: Remain in effect until changed by another global statement or SAS session ends Examples: Titles, Footnotes, Options, Macros, Libname
Comment statements: Ignored by SAS when code is run Used to write comments to yourself or others or comment out code you don’t want to run *comment statement; or /* comment statement */
Programming in SAS • SAS is generally forgiving • Code can be written on a single line or multiple lines • Code and variable names not case sensitive • Even accepts some misspellings • Semicolons are super important • Colors of Enhanced Editor • Always check your log!!! • Often many ways to do the same thing
Where to learn more about SAS http://www.sascommunity.org/wiki/Learning_SAS_-_Resources_You_Can’t_Live_Without Popular Websites Technical papers SAS User Groups Websites Books Classes
Basic Screen Navigation • Editor contains the SAS program to be submitted. • Log contains information about the processing of the SAS program, including any warning and error messages • Output contains reports generated by SAS procedures and DATA steps
Reading raw data set into SAS system • In order to create a SAS data set from a raw data file, you must • Start a DATA step and name the SAS data set being created (DATA statement) • Identify the location of the raw data file to read (INFILE statement) • Describe how to read the data fields from the raw data file (INPUT statement)
Thinking in “SAS” • What is a program? • Algorithm, recipe, set of instructions • How is programming done in SAS? • SAS is like programming in any language: • Step by step instructions • Can create your own routines to process data • Most instructions are set up in a logical manner • SAS is NOT like other languages: • Some syntax is peculiar to SAS • Written specifically for statistics so it isn’t all-purpose • Canned processes that you cannot edit nor can you see the code
Thinking in “SAS” • Creating a program • What is your problem? • How can you find a solution? • What steps need to be taken to find an answer? • Do I need to read in data? • What variables do I need? • Where is the data? • What format is the data in? • How do I need to clean the data? • Are there outliers? • Are there any unexpected values in the data? • How do I need to transform the data? • Are the variables in the form that I need?
Basic rules– organize files • .sas – program file • .log – notes, errors, warnings • .lst – output • .sas7bdat – data file • library – a cabinet to put data in • Default: Work library • temporary, erased after you close the session • Permanent library • libnamemylib “m:\”; • mylib.mydata = a sas data file named “mydata” in library “mylib” • run and recall .sas
/* comment: in green, does not take into calculation */ /* simple example to calculate mean */ /* data are given in the following format */ /* dataset name=grade */ /* data description input name of the variables*/ /* Character variables are mentioned as dollar $*/ /* numerical variables are without dollar sign */ /* for running program press F3 or select and run sign*/ Anil Arekar
data marks; input Name $ Gender $ Status Year marks @@; datalines; A F 2 12 70 B M 1 13 82 C M 2 13 91 D F 2 12 78 E M 1 12 95 F M 2 13 86 ; run; procprint data=marks; run; /* overall mean */ Anil Arekar
procmeans data=marks n mean max min range std; var marks; title 'Summary of marks'; run; /* sexwise means */ procmeans data=marks n mean max min range std; var marks; class Gender; title 'Summary of marks as per sex'; run; /* yearwise means */ procmeans data=marks n mean max min range std; var marks; class year; title 'Summary of marks as per year'; run; Anil Arekar