05-08-2018 09:10 AM
Typically the keyword CALCULATED is required any time a variable is calculated and used within the same query within a RPOC SQL step. However, lately I found that it also works WITHOUT the keyword in a GROUP BY clause.
In the codes below, typically we should use GROUP BY Calculated XID; but it did work without the keyword. Any idea? I guess it's a SAS version issue, where in the later versions the rules for GROUP BY is loosened up?
do block = 4 to 16 by 4;
do i=1 to 3;
create table test as select block, x,
x**2 as xsq,
mean(calculated xsq) as meanXsq,
calculated xsq**.5 as XID
group by XID;
05-08-2018 01:13 PM
The GROUP BY does not default to using variables that come from one of the input tables. In fact usually you will want to use one of the variables that is being included in the output.
However you might need to use CALCULATED if there is confusion between one of the input variable and on of the calculated variables.