Programming the statistical procedures from SAS

Computing the average by variable.

Reply
N/A
Posts: 0

Computing the average by variable.

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
N/A
Posts: 0

Re: Computing the average by variable.

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
Super Contributor
Posts: 281

Re: Computing the average by variable.

PROC MEANS with at BY variable;

or PROC SUMMARY with a CLASS variable
Contributor
Posts: 20

Re: Computing the average by variable.

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;
N/A
Posts: 0

Re: Computing the average by variable.

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
Super Contributor
Super Contributor
Posts: 3,174

Re: Computing the average by variable.

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
Ask a Question
Discussion stats
  • 5 replies
  • 201 views
  • 0 likes
  • 4 in conversation