![]() |
PING
0.9
Statistical data handling and processing in production environment
|
Generate the expression used to calculate the sum of a series of variables for each observation in a SQL procedure.
var : (option) variable(s) for which the sum will be returned; the variable(s) listed in var must be already present (i.e., originally coded in the processed table);calcvar : (option) ibid, however the variable(s) listed in calcvar refer to previously calculated variables (e.g. , within the same SELECT statement).expr : expression for calculating the sum of a series of variables, to be used within a SQL procedure.
Let us consider the following table dsn1:
| a | b |
|---|---|
| -1 | 100 |
| -2 | 101 |
| -3 | 102 |
| -4 | 103 |
| -5 | 104 |
Then it is only necessary to run the following SQL procedure:
so as to create the following table dsn2:
| absa | sum1 | sum2 |
|---|---|---|
| 1 | 99 | 0 |
| 2 | 99 | 0 |
| 3 | 99 | 0 |
| 4 | 99 | 0 |
| 5 | 99 | 0 |
since the calls to macros %sql_operation_sum:
return respectively the expressions:
expr1=ifn(not missing(a) or not missing(b), (coalesce(a,0)+coalesce(b,0)), .), andexpr2=ifn(not missing(a) or not missing(calculated absa), (coalesce(a,0)+coalesce(calculated absa,0)), .) missing(calculated absa))), .).%sql_operation_sum is a wrapper to L. Joseph's original %SumOf macro. Original source code (no license, no disclaimer) is available at http://www.medicine.mcgill.ca/epidemiology/joseph/pbelisle/MeanOf.html..).%sql_operation_mean, %sql_operation_any, %sql_operation_count.