1 / 34

HRP 223 – 2008

HRP 223 – 2008. Topic 3 – Manipulating Data with SQL and EG. Planning an Analysis. Think before you code. First write out all the steps as notes in an EG project. Connect the nodes to the tasks and you have a self documented program. BMI and Diabetes.

harris
Download Presentation

HRP 223 – 2008

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. HRP 223 – 2008 Topic 3 – Manipulating Data with SQL and EG

  2. Planning an Analysis Think before you code. First write out all the steps as notes in an EG project. Connect the nodes to the tasks and you have a self documented program.

  3. BMI and Diabetes

  4. You want to have well labeled nodes in the flowchart. Be sure to label your library icon with the same name as the library.

  5. Spaghetti and Spiderwebs As I work on a project, I have the options set to show me the logs (and sometimes the generated code). Once I check the log I delete the log node from the flow.

  6. Be sure to check the log after you submit your code. If it has only notes saying data or views were created and the number of seconds each task took, then delete the log node and move on to the next step.

  7. BMI Analysis (take 2) • Begin with the notes and do each task. • Check for a relationship between two continuous variables. • Do a scatter plot. • Look at Karl Pearson’s correlation coefficient. • Why do some people report R and others use R-squared?

  8. A better solution would be to drop this bad record early on. Be careful of complete case analyses. If you have lots of variables, you do analyses on very different subsets of subjects.

  9. Assignment 2 Even if you spend a ridiculous amount of time looking (10-15 minutes), you probably will not spot the problems. If you import the data using the import wizard, it looks like the two files are identical. If you use import code, fix your registry, and specify mixed data in each column, you will notice that both columns come in as character variables!

  10. Compare Two Files The MIXED line is missing. Wouldn’t it be handy if SAS could compare two files and tell you what cells have actual character data? If you import the data ignoring the possibility of characters, you will get data sets where the variables are numeric and the “cells” that originally had character data are set to missing.

  11. Two Data Sets Labs has two character variables. LabsNotMixed has two numeric variables (one is formatted so it looks like a date).

  12. Manual or Automatic Change You can manually change the format in this dataset or have it automatically make the change in a new dataset. If you make the manual change, the next time you import the data the format will reset to DDMMMYYYY.

  13. Reformatted The formats are still not identical because the Excel file has no leading zeros when the month or day is less than 10. You need to make the same format in Excel….

  14. Custom Excel Formats You can write your own custom formats in Excel. Tell it to make a format that shows two digits for month and date, and four digits for year.

  15. Same Dates (sort of) Now the two dates display the same way except one is stored as a character variable and the other is numeric.

  16. Compare? There is a great comparison procedure in SAS but it wants the variables to be of the same type.

  17. Try to compare the two files. After it imports, the numeric version is missing data. Convert it to be a character variable and then compare the two variables.

  18. The put Function • Recall functions in SAS take 1 or more arguments inside parentheses and they return a value. • theSin = sin(1) • There is a function called put that takes a numeric variable and returns a character string.

  19. put( variableName, format. )

  20. Numeric and Character

  21. Same Voodoo on Dates Here we want to put the date as a character string after applying the MM/DD/YYYY format.

  22. Converting this Numeric to Character In the case of the assignment 2 data we don’t want to use the best. format because we have to think about the number of decimal places. The value is displayed in Excel and imported as a character string rounded to three decimal places. We also want to compress out any blank spaces:

  23. The Differences Excel and SAS use different algorithms for rounding…. You can also spot the bad date plus the lab value that is below the detectable limit of the assay.

  24. Dealing with Problems • Say you input a numeric variable and it has some bad values in it. This causes it to import as a character variable if you are paying attention (using mixed). You could use the input function and convert it to numeric. This, if not done carefully, will result in missing values. • newNumeric = input(oldCharacter, 8.)

  25. Not Many Values If your variable has only a few values you can use the Describe > One Way Frequency menu to see all the values, then change the scores with the Filter and Query tool.

  26. Filter and Query Recode You can recode a problematic variable so that it will become a new numeric variable with the bad values recoded to different types of null.

  27. Recode

  28. After Once the data has been recoded you can calculate statistics on it. Be sure to add in a format so the values will display nicely.

  29. Distinct Records There will be times when you want to get the distinct IDs (or a distinct set of variables) from a dataset. Just check on the select distinct rows checkbox.

  30. Dates Rather than dealing with the headaches of dates, a lot of databases split the dates into three variables: month, day and year. If the dates are split, it allows you store incomplete dates. You can use the MDY function to combine the 3 parts into a date variable. theDate = mdy(theMonth, theDay, theYear)

  31. Remember a Display Format SAS does not apply a date format automatically.

More Related