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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1598 views
  • 0 likes
  • 4 in conversation