Biostat Lab Section SAS functions - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Biostat Lab Section SAS functions

Description:

When planning modifications to SAS datasets, examine the many SAS ... CEIL - returns the smallest integer greater than or equal to the argument. newx = CEIL (x) ... – PowerPoint PPT presentation

Number of Views:75
Avg rating:3.0/5.0
Slides: 11
Provided by: carr133
Category:
Tags: sas | biostat | ceil | functions | lab | section

less

Transcript and Presenter's Notes

Title: Biostat Lab Section SAS functions


1
Biostat Lab Section SAS functions
  • Yu-Fen Li

2
SAS functions
  • When planning modifications to SAS datasets,
    examine the many SAS functions that are available
  • SAS has many built in functions that greatly
    reduce the need to enter commands
  • SAS functions are pre-written expressions that
    provide shortcuts for many calculations and
    manipulations of data

3
SAS Operators
  • Operators
  • comparison operator lt, gt, and
  • addition (), subtraction (-), division (/), and
    multiplication ()
  • meanscore (score1 score2) / 2
  • A missing value is assigned if any argument is
    missing
  • concatenation operator
  • idnum schcode id

4
Some Arithmetic Functions
  • SQRT - calculates the square root
  • newx SQRT(x)
  • LOG/LOG2/LOG10 - calculates the logarithm to the
    base e/2/10
  • newx LOG (x)
  • ABS - returns the absolute value
  • newx ABS (x)
  • MOD - calculates the remainder
  • newx MOD (x,3)

x4 gt newx2
x4 gt newx1.3863
x-4 gt newx4
x4 gt newx1
5
Some Sample Statistic Functions
  • MEAN - computes the arithmetic mean (average)
  • meanz MEAN (4,9,3,8,.)
  • CV - calculates the coefficient of variation
  • MAX - returns the largest value
  • MIN - returns the smallest value
  • N - returns the number of nonmissing arguments
  • NMISS - returns the number of missing arguments
  • RANGE - calculates the range
  • STD - calculates the standard deviation
  • STDERR - calculates the standard error of the
    mean
  • SUM - calculates the sum of the arguments

WHAT is your answer?
6
Some Truncation Functions
x4.972
  • CEIL - returns the smallest integer greater than
    or equal to the argument
  • newx CEIL (x)
  • FLOOR - returns the largest integer less than or
    equal to the argument
  • newx FLOOR (x)
  • INT - returns the integer value
  • newx INT (x)
  • ROUND - rounds a value to the nearest round-off
    unit
  • newx1 ROUND (x, 0.01)
  • newx2 ROUND (x, 0.1)

newx5
newx4
newx4
newx14.97
newx25
7
Some Character Functions
XaBC.DdF(Xy)
  • SCAN - scans for words
  • newx SCAN (x,2,.)
  • SUBSTR - extracts a substring
  • newx SUBSTR (x,3,2)
  • TRIM - removes trailing blanks
  • newx TRIM (x)
  • LOWCASE - converts all to lowercase
  • newx LOWCASE (x)
  • UPCASE - converts to uppercase
  • newx UPCASE (x)

DdF(Xy)
C.
aBC.DdF(Xy)
abc.ddf(xy)
ABC.DDF(XY)
8
Some Date and Time Functions
  • MDY - returns a SAS date value from month, day,
    and year
  • For example, MDY(10,17,91) returns the SAS date
    value '17OCT91'D
  • DAY - returns the day of the month from a SAS
    date value
  • DAY ('17OCT91'D) give a number 17
  • MONTH - returns the month from a SAS date value
    or literal
  • MONTH ('17OCT91'D) give a number 10
  • YEAR - returns the year from a SAS date value
  • YEAR ('17OCT91'D) give a 4-digit number 1991

9
In-Class Assignment
  • Generate the following data in SAS
  • Calculate the mean score of 3 tests for each
    student
  • a missing score is counted as a test of score 0

10
In-Class Assignment
  • Calculate the age for all students
  • Age round up (REF dob)/365.25 to a integer
  • REF is set as 1/1/2008
  • List the mean score for students whose name
    starts with a J
  • List the mean score for students whose birth year
    was in 80s
Write a Comment
User Comments (0)
About PowerShow.com