1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University....

69
1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and international treaties. Unauthorized reproduction of this presentation, or any portion of it, may result in severe civil and criminal penalties and will be prosecuted to maximum extent possible under the law.
  • date post

    15-Jan-2016
  • Category

    Documents

  • view

    215
  • download

    0

Transcript of 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University....

Page 1: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

1

Lab 1

HRP223 – 2010October 6, 2010

Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved.Warning: This presentation is protected by copyright law and international treaties. Unauthorized reproduction of this presentation, or any portion of it, may result in severe civil and criminal penalties and will be prosecuted to maximum extent possible under the law.

Page 2: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

2

Topics For Today• Setup Windows

– Show the file extensions– Set up folders– Setup Office– Using DOS

• The parts of SAS• Configure SAS Enterprise Guide

– Application options– Keyboard macros

• Using SAS – Libraries– Subsets– Creating toy data sets– Loading real data sets– Descriptive statistics and graphics

Page 3: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

3

Show File Extensions (Suffixes) in XP

2

3 Uncheck

41

5

Setup Windows

Page 4: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

4Add a new folder called projectsDouble click it (to open it)

Setup Windows

Page 5: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

5

The projects folder is inside of the c drive.This path is abbreviated c:\ProjectsIf you hate to type, copy and paste it from here.

You can choose the view of the contents by pushing this button. I usually use the details view.

Setup Windows

Page 6: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

6

Add a folder here called HPR223Inside that folder add a folder called Lab1Also in the c:\projects\hrp223 folder, add a folder called assignment2

Setup Windows

Page 7: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

7

If there is a project that you are working, on mark the folder with a new icon.

1) right click

2) Choose properties

3) Click Customize

4) Pick an icon

Setup Windows

Page 8: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

8

If you need to rename anything in windows, click it and push the F2 key.If you want to get to My Computer quickly, push the Windows key with eIf you want to get to the desktop quickly, push Windows dIf you want to search your hard drive, push Windows f

Setup Windows

Page 9: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

9

Download the letters and Numbers Excel file from the class website and confirm the file suffix is still xlsx

Setup Windows

Page 10: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

10

Office 2007 Voodoo

• Add the properties button to the quick access bar.

• Add the Switch Window button to the quick access bar.

• Add the folders you use a lot to the open and save dialog boxes.

Setup Office

Page 11: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

11

Setup Office

Page 12: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

12

Ribbon to Quick Access

• You can add things to the quick access bar by right clicking on them.

Setup Office

Page 13: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

13

Right click down here

You can add this location to the Open and Save As dialog boxes for all of Office.

Setup Office

Page 14: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

14

Allowing EG to Talk to DOS

• There are times when you want to have SAS or EG ask Windows to do a task. For example, you may want to have a folder (directory) created automatically or you may want to set the folder where SAS should look for files or where results will be stored by default.

• The easiest way to do this is to type programming commands in DOS (the file manipulation system that predates modern Microsoft Windows).

• Another word for the operating system is the shell.

Using DOS

Page 15: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

15

DOS Stuff

• There are only a few commands you want to bother with– mkdir = make a directory (AKA folder)

mkdir c:\blah

– del = delete everythingdel /Q c:\blah\*.*

– cd = change to a directorycd c:\blah

Using DOS

Page 16: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

16

Shell Escape

• In SAS programs you can type DOS commands like this:

X "dos stuff goes here";These are called shell escapes. Obviously, shell escapes are dangerous tricks that give you the power to do all kinds of mischief including erasing a hard drive.

• By default, Enterprise Guide does not allow them. You need to tweak the registry to turn the functionality back on.

Using DOS

Page 17: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

17

Shell Escape Commands in EG

• Tweak to the registry:1. Start => Run => enter REGEDIT => OK.2. Select hkey_classes_root => clsid => {440196D4..... => localserver32.3. Right-mouse on Default and select Modify. Be careful here.4. Remove -noxcmd (should be the last item in the list) => Ok.5. View => Refresh.6. Exit the Registry window. 7. Reboot

• Backup your registry before you change anything: support.microsoft.com/kb/322756

• Ask for help if you have the slightest question.

Using DOS

Page 18: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

18

The parts of SASTalking to programmers….

WYSIWYG – pronounced wizzywig = what you see is what you getGUI – pronounced gooey = graphical user interface (the point and click stuff)

WYSIWYG graphics editing that works only with SAS.

The SAS engine with an old GUI

A useful GUI for proc powerA GUI for SAS

Help files are in here

Page 19: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

19

Change the Default File Location

• On every machine you use, you should change the default file location to the work library. Do this once per machine.

Configure SAS

Page 20: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

20

Click 1st

Click 2x

Configure SAS

Page 21: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

21

Other Options

• To save your sanity, make this change to the options.

Check this box on

Configure SAS

Page 22: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

22

Custom Code for Graphics

• Analyses in SAS 9.2 can have extra high resolution graphics. Permanently turn them on.

Configure SAS

Page 23: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

23

Making Code Easy

• To make it easier to write code I have prepared keyboard macros that will let you fill in the blanks in code rather than having to memorize the details of the language. – Download the file

www.stanford.edu/class/hrp223/2010/macros2010.kmf

– Open a code node, then from the Program menu, choose Editor Macros and click Macros.

– Choose Import… and select the file you downloaded

Configure SAS

Page 24: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

24

Configure SAS

Page 25: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

25

Using the Macros

• When you type the name of an analysis or data management procedure, a "tool tip" will appear. Push the Tab key to have SAS include the code I wrote.

Configure SAS

Page 26: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

26

Permanent Store

• I suggest that you save your data into the temporary work library by default.

• If you have a huge file which you only want to import once, or if you want to keep a permanent copy of a SAS data file, you will want to set up a permanent library.– This is just a fancy way of specifying what folder

SAS should use to save the .sas7bdat data files.

Using SAS

Page 27: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

27

Custom Icons

• SAS 9.2 can not assign a library to a folder that has ever had a custom icon. It is OK to use the custom icon to mark a folder as an active project but you will need to add a folder inside of it with a normal icon to hold the data.

C:\projects\hrp223\lab1 has a custom icon because it is an active project

C:\projects\hrp223\lab1\data will hold the data for this project

Page 28: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

28

• I suggest you use the c:\projects folder on your hard drive but if you do not have permission, you can use the desktop. To point EG to a library on your desktop you need to navigate to a path like: c:\Documents and Settings\blah\Desktop where blah is your account name on the PC.

Page 29: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

29

Download the Data (1)

• Make the directory to hold the data… with DOS!!!– Click the windows start button– Click Run…– Type cmd and push enter– type mkdir c:\projects\hrp223\lab1 and push enter

I go here for DOS questions: www.computerhope.com/msdos.htm

Page 30: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

30

Download the Data (2)

• Download the data from here:www.stanford.edu/class/hrp223/2009/data/lettersAndNumbers.xlsx

Page 31: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

31

Importing the Easy Way

• The most bulletproof way for importing with EG 4.2 is to use the import wizard.

Using SAS Libraries

Page 32: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

32

Page 33: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

33

Using SAS Libraries

If you have problems with access to folders you can use the DesktopC:\Documents and Settings\AccountName\Desktop

Page 34: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

34

You must click on the folder you want to use as a library. Expanding the tree is not enough.

BAD Good

Using SAS Libraries

Page 35: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

35

1st rename the node to match the library name

2nd add a line to the flowchart connecting the library to the import. It just looks good.

Using SAS Libraries

Page 36: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

36

Using SAS Libraries

Page 37: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

37

Using SAS Libraries

Page 38: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

38

Playing with Data

• Once the data is imported, you can add code “nodes” to the flowchart or use the graphical user interface to tweak the data and do analyses.

Complex changes

Quick and easy subset and sorting

Using SAS Data

Page 39: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

39

Using SAS Data

Page 40: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

40

It gives you more options as you add in sort variables.

SQL is built behind the scenes.

Using SAS Data

Page 41: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

41

Converting Characters to Numbers

• If you want to convert a variable that is a character into numeric use the input function. Keep in mind that all values that include non-numeric values will be erased.

input(originalName, N.D)

Using SAS Data

Page 42: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

42

All the functionality of the Filter and Sort tool are in

the Query Builder

You create new variables with this button.

drag

Page 43: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

43

Using SAS Data

Page 44: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

44

Give the node a meaningful name.

Name the new dataset

You can delete the character version of

score.

Page 45: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

45

Context sensitive menus help you describe the data you are browsing.

Using SAS Data

Page 46: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

46

Descriptive Statistics

drag

Using SAS Descriptive

Page 47: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

47

Page 48: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

48

Toy Data Sets

• It used to be that you needed to memorize lots of arcane syntax to accomplish even the easiest of tasks, like making a toy data set.

Using SAS for Toy Data

Page 49: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

49

Wizards take more time than typing but they are easy to use.

They can’t do some complicated tasks.

Using SAS for Toy Data

Page 50: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

50

• The EG data manipulation tools use SQL.• For simple tasks you can use either language (or point

and click) but for complicated tasks, each has advantages which I will eventually show you.

Data Step vs. Proc SQLUsing SAS for Toy Data

Page 51: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

51

Export from REDCap importing into SASUsing SAS for Real Data

Page 52: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

52

Page 53: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

53

Using SAS for Real Data

Page 54: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

54

Using SAS for Real Data

The path is missing.Add it in and run the program.

Page 55: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

55

Using SAS for Real Data

Page 56: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

56

Instead of modifying that file….

• Download my REDCap loading EG project from here:

www.stanford.edu/class/hrp223/2010/REDCapLoad20100802.egp

Page 57: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

57

Tweak the EG Project

This is a program that loads the data exported by REDCap. Double click

this.

Page 58: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

58

Enter today’s date in yyyyMMdd format. The

output will go into a folder with this name.

This is the path to where you saved the files. Note

no final \

This is the name of the file you exported.

Edit my Project Shell

Page 59: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

59

Subset to get the Females.Using SAS for Real Data

Page 60: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

60

Grab all variables then take away sex.Using SAS for Real Data

Page 61: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

61

Remove the gender variable.Using SAS for Real Data

Page 62: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

62

Enterprise Guide writes SQL.

Using SAS for Real Data

Page 63: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

63

Page 64: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

64

SAS Data Step vs. SQL

• SQL is a nearly universal language for accessing, querying and changing data in databases.– Most tasks can be easily done by having the SAS GUI

write SQL for you.• Data step programming is the language used only

by SAS.– Some frequently done tasks can be done quickly and

easily with data step programming.• splitting tables into several new tables• processing groups of records

Using SAS for Real Data

Page 65: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

65

Procedures

• In addition to data step programming, the other major part of the SAS programming language is the use of procedures for analysis (and complex data manipulation).

• You can memorize the syntax and write PROC code or you can use EG and have it do the work for you.

Using SAS for Real Data

Page 66: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

66

Using SAS for Real Data

Page 67: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

67

Drag and drop height into the analysis variable role.Then check on a histogram plot and tell it to insert the mean into the plot.

Using SAS for Real Data

Page 68: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

68

Using SAS for Real Data

Page 69: 1 Lab 1 HRP223 – 2010 October 6, 2010 Copyright © 1999-2010 Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.

69

Using SAS for Real Data