I am trying to write a function that will take the average of a number of columns (rather than average of column in a number of rows)(trying to ghost a SAS function called mean)
select
meanof('var1,var2,var3')
from mytable
on data (var1,var2,var3)
2,4,6
6,8,10
would return
meannof(var1,var2,var3)
4
8
I started parsing the string 'var1,var2,var3' and put it in a varrray but struggling to know how to get it to substitute the column name for the column values tried execute immediate. Guess I could do it as a procedure but interested in writing this as a function becuase want to use it in statements like...
select
least(var1,var2,var3,var4),
meanof(var1,var2,var4,var4)
from mytable
Am I going the right way trying execute immediate, will I be able to write this as a function?
Any help / or steer gratefully acepted
select
meanof('var1,var2,var3')
from mytable
on data (var1,var2,var3)
2,4,6
6,8,10
would return
meannof(var1,var2,var3)
4
8
I started parsing the string 'var1,var2,var3' and put it in a varrray but struggling to know how to get it to substitute the column name for the column values tried execute immediate. Guess I could do it as a procedure but interested in writing this as a function becuase want to use it in statements like...
select
least(var1,var2,var3,var4),
meanof(var1,var2,var4,var4)
from mytable
Am I going the right way trying execute immediate, will I be able to write this as a function?
Any help / or steer gratefully acepted