BookmarkSubscribeRSS Feed
deleted_user
Not applicable
How can I create a new variable as an average by.

Example: I need code to get the avg_hight in class:

class hight avg_hight_in _class
a 6 7
a 7 7
a 8 7
b 4 5
b 5 5
b 6 5
5 REPLIES 5
deleted_user
Not applicable
I mean in the above example, I got a table of three columns:
Class, Hight and Average hight.
There are two classes, thre observations each.
What code can give me the third column (The average in class)?
Malek
Paige
Quartz | Level 8
PROC MEANS with at BY variable;

or PROC SUMMARY with a CLASS variable
sfleming
Calcite | Level 5
One way would be:

proc sql;
create table as
select class, height, mean(height) as avg_height_in _class
from
group by class, height ;
quit;
deleted_user
Not applicable
Thank you sfleming, I used the code you've just given to me as follows:

proc sql;
create table as
select ind_qtr_qnt, lag4_roa, mean(lag4_roa) as avg_lag4_roa
from
group by ind_qtr_qnt, lag4_roa ;
quit;

But it didn't work and I got the following log message:

.
14 proc sql;
15 create table as
-
22
NOTE: The SAS System was unable to open the macro library referenced by the SASMSTORE = libref
SASUSER.
15 create table as
--------------
201
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string.

ERROR 201-322: The option is not recognized and will be ignored.

16 select ind_qtr_qnt, lag4_roa, mean(lag4_roa) as avg_lag4_roa
17 from
-
22
--------------
201
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (,
CONNECTION, DICTIONARY.

ERROR 201-322: The option is not recognized and will be ignored.

18 group by ind_qtr_qnt, lag4_roa ;
19 quit;
NOTE: The SAS System was unable to open the macro library referenced by the SASMSTORE = libref
SASUSER.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Omit the brackets - they are to designate "your input/output file" in the example.

Scott Barry
SBBWorks, Inc.

DOC reference from SAS support website:

http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/a002536894.htm

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 ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1398 views
  • 0 likes
  • 4 in conversation