{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Handout04 - Lecture 4 1 Editor keyboard shortcuts 2 More on...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 4 1. Editor keyboard shortcuts 2. More on merging 3. First and Last variables 4. Data set options 5. Finding unmatched or discrepant observations in a merge 6. Date and time data 1 Keyboard shortcuts: Tools > Options > Enhanced Editor Keys • Comment out lines of code using CTRL+/ • Uncomment using CTRL+SHIFT+/ • Create/remove bookmark: CTRL+F2 • Move to next/previous bookmark with F2/SHIFT+F2 • Create abbreviations using CTRL+SHIFT+A • Convert the selected text to lowercase CTRL+SHIFT+L, uppercase CTRL+SHIFT+U Select columns: hold ALT key while selecting Default list on course website (from SAS) 2
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Structural limitations in SAS processing 1. SAS can only work with data contained in a dataset. Data set: rows are observations, columns are variables. 2. SAS can only process one dataset at a time. To work with 2 datasets, combine them ( merge or set ). 3. Within a data step, SAS only works with one observation at a time. (There are ways to retain information from one observation to the next.) 3 More on MERGE 1. One-to-one merge: single observation for each ID in each data set (LSB §6.4) Data A Data B id color mass id mass pH 12 orange 3650 13 11267 7.8 13 blue 3877 14 3568 8.2 15 yellow 4103 15 4103 5.1 2. One-to-many merge : single observation ( xbar, SD ) in first data set merged with every observation in second data set (LSB §6.5) 4
Image of page 2
Many-to-many MERGE: multiple observations per ID Want to merge two spreadsheets with clinical data recorded at each visit. Data E Data F id visit DBP id visit weight 101 1 77 101 1 145 101 2 75 101 2 149 . 3 80 101 3 152 102 1 71 102 1 181 102 2 74 102 2 176 102 3 68 5 Let’s try code that worked before: proc sort data=E; by id; sort by ID first proc sort data=F; by id; data G; merge E F; by id; SAS LOG NOTES: MERGE statement has more than one data set with repeats of BY values. There were 6 observations read from the data set WORK.E. There were 5 observations read from the data set WORK.F. The data set WORK.G has 7 observations and 4 variables. Extra observation? 6
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Data E Data F id visit DBP id visit weight 101 1 77 101 1 145 101 2 75 101 2 149 . 3 80 101 3 152 102 1 71 102 1 181 102 2 74 102 2 176 102 3 68 Data G: Obs id visit dbp weight 1 . 3 80 . 2 101 1 77 145 3 101 2 75 149 4 101 3 75 152 5 102 1 71 181 6 102 2 74 176 7 102 3 68 176 where did these come from? 7 Within each ID, SAS is merging without any matching variable. Sort by as many variables as needed to identify each observation. Then merge by all of them. Here, ID and visit are enough. Data E Data F id visit DBP id visit weight 101 1 77 101 1 145 101 2 75 101 2 149 . 3 80 101 3 152 102 1 71 102 1 181 102 2 74 102 2 176 102 3 68 8
Image of page 4
proc sort data=E; by id visit; proc sort data=F; by id visit; data K; merge E F; by id visit; proc print data=K; Obs id visit dbp weight 1 . 3 80 .
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern