BookmarkSubscribeRSS Feed
Chunbo
Calcite | Level 5

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? 

 

data block;
  do block = 4 to 16 by 4;
      do i=1 to 3;
      x=block+i;
       output;
      end;
  end;
  drop i;
run;

proc sql;
    create table test as select block, x,
    x**2 as xsq,
    mean(calculated xsq) as meanXsq,
    calculated xsq**.5 as XID
from block
group by XID;
quit;

2 REPLIES 2
Tom
Super User Tom
Super User

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.

 

Chunbo
Calcite | Level 5
That makes sense. Thanks, Tom!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1774 views
  • 0 likes
  • 2 in conversation