Let's load in our toy data set again


In [ ]:

We want to calculate BMI, how do we do that?


In [ ]:

since we know how to go line by line through the list, let's go calculate BMI


In [ ]:

but what if we want to use BMI on another data set?

what if we just need to calculate bmi for some other reason?

what if this is spread out through out our notebook/script/code??

functions to the resuce!

functions, just like mathematical functions, take in some input (that you specify) does some stuff with it, and output something


In [ ]:
# function to calculate BMI

Let's do the previous examples again, but this time using the new function we made


In [ ]:

See isn't that so much better?

not only is the code 'simplier', it is easier to read, easier to maintain, and if you find a mistake in your function, you change it once, and everytime it is called again will be updated

gone are the ways where you 'missed a spot'

can SAS give you that????


In [ ]: