1 / 20

Summer SAS Workshop Lecture 2

Summer SAS Workshop Lecture 2. Summer SAS Workshop Lecture 2. I’ve got Data…how do I get started? Libname Review How do you do arithmetic operations in SAS? Proc Means Proc Freq Proc Print Title Statements Libname Quiz More Practice!. Part I of Lecture 2. The DATA Step

drew
Télécharger la présentation

Summer SAS Workshop Lecture 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Summer SAS WorkshopLecture 2

  2. Summer SAS WorkshopLecture 2 • I’ve got Data…how do I get started? • Libname Review • How do you do arithmetic operations in SAS? • Proc Means • Proc Freq • Proc Print • Title Statements • Libname Quiz • More Practice!

  3. Part I of Lecture 2 The DATA Step • Getting Data into SAS • Libname Review • Adding variables…doing arithmetic • SAS Dates

  4. Get to know your data • Before you do anything, review what format your data is in currently. Look at the number and type of variables, and number of observations (rows) you have in your data set(s). KNOW YOUR DATA! • Before you can analyze your data with SAS software, your data must be in a form that SAS can read • What are some ways to get data ready to analyze in SAS?

  5. What kind of data do you have? • Data that is already in the form of a SAS data set. • Can right away be used for direct manipulation and analysis • Large files of external raw (non-SAS) data. • Use Import functions, database copy software (ex: DBMSCopy), or other ways... • Small pieces of data that are not yet in a SAS data set. (What we have been doing so far-Internal Data) • Enter as raw data directly into your Data Step (Keywords INPUT and CARDS)

  6. 1) If you already have SAS data sets • If you already have SAS data sets, first set up a library statement pointing to where your data is located. Libname heart ‘C:\DATA’; • Next start using the data sets directly. Data icd9HF; Set heart.meps; If icd9 = 123.6; Run; Proc Freq Data = icd9HF; *Produce frequencies for Heart Failure patients by gender and race variables; Tables gender race; Run;

  7. Temporary vs. Permanent SAS Data Sets • A two level name…a Temporary SAS data set is the one level name that we have been using: LibraryName.DataSetName • Temporary SAS data sets will not exist when you shut down the instance of SAS in which they were created. Data new; Set AIDS; Run; • First define a SAS Library (Libref)

  8. LIBNAME Statement • Use this statement to define your SAS Library location before using your SAS data sets Example: LIBNAME ABC ‘C:\SASDATA’; Proc Means Data = ABC.EX4A; Var X Y Z; Run;

  9. Data one; Input Name$ Bdate mmddyy10. Age Index; cards; Ann 04/22/1930 76 5 Cathy 08/06/1962 43 9 Rebecca 11/12/1983 22 2 ; Run; *Reading internal data to create SAS data set ‘one’; INPUT statement example

  10. SAS Dates • A SAS date is the number of days since January 1, 1960 Date SAS date value January 1, 1959 -365 January 1, 1960 0 January 1, 1961 366 January 1, 2001 14976

  11. Formatting Dates • Informats – To read variables that are dates, you use formatted style input INPUT BirthDate MMDDYY10. • Formats – If you print SAS date values, SAS will by default print the actual value, the number of days since January 1, 1960. The Format statement below tells SAS to print the variable BirthDate using the DDMMYY8. Format Format BirthDate DDMMYY8.

  12. Why are SAS dates done this way? • SAS can use the SAS date to calculate many important things, just as it would any other numeric variable. AGE = INT ((ADMIT – DOB) / 365.25); (Calculates patient age at admission) LEN_STAY = DISCHRG – ADMIT +1; (Calculates the length of stay including the admission day and the discharge day)

  13. Lets Try this… • Go to the website and unzip the Clinical2 SAS data file into your C:\DATA folder. • Follow the steps (see slide 6) to make a copy of the data as a temporary SAS data set. • Create a new variable from the HBeats variable (heart beats per 10 second count). Create and HR variable (beats per minute). • Create a new Age at Baseline variable. • Format the Birthdate variable as mmddyy10. and the BaselineDt variable as DATE9. • Perform a Proc Contents of the new data set. • Perform a Proc Print of the new data set.

  14. Difficult, dirty data…SAS doesn’t like it and neither do we

  15. Part II of Lecture 2 The DATA Step • Proc Freq • Proc Means • Which variables from the clinical2 data set would you use in each for each of these Procs?

  16. PROC FREQ • Shows the distribution of categorical data values PROC FREQ Data=datasetname; TABLES variable-combinations / option(s); RUN; • One-way freq tables: TABLES YearsEducation; • Cross-tabulation: TABLES Sex*YearsEducation;

  17. PROC MEANS • Produces simple statistics such as the mean value, standard deviation, and minimum and maximum values PROC Means Data=datasetname; Var variablenames; RUN;

  18. Lets Perform these… • Create a Proc Freq on the clinical2 data set. Choose the appropriate variables. • Create a Proc Means on the clinical2 data set. Choose the appropriate variables.

  19. Part III of Lecture 2 Libname Quiz!

  20. Lets try to do HW 1 together… • We will use the samples of TPA data to produce descriptive statistics and graphics in order to reproduce some of the stats in Tables 1 and 2 of the TPA paper. • Readings: Readings for clarification of Libname etc. for start of classes: Cody Chapters 12-14      

More Related