1 / 12

EPIB 698C Lecture 5

EPIB 698C Lecture 5. Raul Cruz-Cano. Creating and Redefining Variables. You can create and redefine variables with assignment statements as follows: Variable =expression. Vector Notation. Home gardener's data.

wade-finch
Download Presentation

EPIB 698C Lecture 5

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. EPIB 698C Lecture 5 Raul Cruz-Cano

  2. Creating and Redefining Variables • You can create and redefine variables with assignment statements as follows: Variable =expression Vector Notation

  3. Home gardener's data • Gardeners were asked to estimate the pounds they harvested for four corps: tomatoes, zucchini, peas and grapes. Here is the data: Gregor 10 2 40 0 Molly 15 5 10 1000 Luther 50 10 15 50 Susan 20 0 . 20 • Task: • add new variable group with a value of 14; • add variable type to indicate home gardener; • Create a new variable zucchini_1 which equals to zucchini*10 • derive total pounds of corps for each gardener; • derive % of tomatoes for each gardener

  4. Home gardener's data DATA homegarden; INFILE‘C:\garden.txt'; INPUT Name $ 1-7 Tomato Zucchini Peas grapes; group = 14; Type = 'home'; Zucchini_1= Zucchini * 10; Total=tomato + zucchini_1 + peas + grapes; PerTom = (Tomato / Total) * 100; Run; CODE

  5. Home gardener's data • Check the log window: Missing values were generated as a result of performing an operation on missing values. • Since for the last subject, we have missing values for peas, so we the variable total and PerTom, which are calculated from peas, are set to missing

  6. SAS functions • SAS has over 400 functions, with the following general form: Function-name (argument, argument, …) • All functions must have parentheses even if they don’t require any arguments • Example: • X=Int(log(10)); • Mean_score = mean(score1, score2, score3); The Mean function returns mean of non-missing arguments, which differs from simply adding and dividing by their number, which would return a missing values if any arguments are missing

  7. Common Functions And Operators • Functions ABS: absolute value EXP: exponential LOG: natural logarithm MAX and MIN: maximum and minimum SQRT: square root SUM: sum of variables Example:SUM (of x1-x10, x21) • Arithmetic: +, -, *, /, ** (not ^)

  8. More SAS functions CODE

  9. Selected date functions

  10. Working with SAS Date • A SAS date is a numeric value equal to the number of days since Jan. 1, 1960. For example: CODE

  11. Example: pumpkin carving contest data • This data contains contestant’s name , age, type of pumpkin (carved or decorated), date of entry and the scores from 5 judges. Alicia Grossman 13 c 10-28-2003 7.8 6.5 7.2 8.0 7.9 Matthew Lee 9 D 10-30-2003 6.5 5.9 6.8 6.0 8.1 Elizabeth Garcia 10 C 10-29-2003 8.9 7.9 8.5 9.0 8.8 Lori Newcombe 6 D 10-30-2003 6.7 5.6 4.9 5.2 6.1 Jose Martinez 7 d 10-31-2003 8.9 9.510.0 9.7 9.0 Brian Williams 11 C 10-29-2003 7.8 8.4 8.5 7.9 8.0 • We will derive the means scores using the “Mean” function • Transform values of “type” to upper case • Get the day of the month from the SAS date

  12. Example: pumpkin carving contest data DATA contest; INFILE‘C:\pumpkin.txt'; INPUT Name $16. Age Type $ @23 Date MMDDYY10. (Scr1 Scr2 Scr3 Scr4 Scr5) (4.1); AvgScore= MEAN(Scr1,Scr2,Scr3,Scr4, Scr5); DayEntered = DAY(Date); Type = UPCASE(Type); run; CODE

More Related