Help using Base SAS procedures

Cross sectional averages

Accepted Solution Solved
Reply
Contributor
Posts: 60
Accepted Solution

Cross sectional averages

Hi

I am looking to calculate cross sectional averages.

Is this possible on sas?

I have attached a small sample of my data below.


Accepted Solutions
Solution
‎08-20-2012 11:09 AM
Respected Advisor
Posts: 2,655

Re: Cross sectional averages

proc means data=yourdata nway;

class bmdecile cfdecile;

var RET VWRETD EWRETD;

run;

This will give the 300 means, standard deviations, mins and maxes as output.

If you want a dataset as output, either switch to proc summary or add the following:

proc means data=yourdata nway noprint;

class bmdecile cfdecile;

var RET VWRETD EWRETD;

output out=meandata mean=/autoname;

run;


Steve Denham

View solution in original post


All Replies
Super User
Posts: 5,256

Re: Cross sectional averages

I'm not sure if understand you correctly, but I think you can start with proc means, or SQL (BMDECILE, CFDECILE, select avg(RET), avg(VWRETD), avg(EWRETD) from x group by BMDECILE, CFDECILESmiley Wink

Data never sleeps
Contributor
Posts: 60

Re: Cross sectional averages

Could you please be more specific?

Super User
Posts: 5,256

Re: Cross sectional averages

Sample SQL:

Proc sql;

select 

BMDECILE, CFDECILE, avg(RET) as retavg, avg(VWRETD) as vwretdavg, avg(EWRETD) as ewretdavg

from x.y

group by BMDECILE, CFDECILE;

quit;

Data never sleeps
New Contributor
Posts: 4

Re: Cross sectional averages

%macro avmacr;

%do i=1 %to 10;

data avgs&i;

set v4;

avg=mean(of RET VWRETD EWRETD);

where BMDECILE=&i and CFDECILE=&i;

%end;

run;

%mend;

%avmacr;

here you get 10 datasets and using set to combine all this 10  datasets.

Solution
‎08-20-2012 11:09 AM
Respected Advisor
Posts: 2,655

Re: Cross sectional averages

proc means data=yourdata nway;

class bmdecile cfdecile;

var RET VWRETD EWRETD;

run;

This will give the 300 means, standard deviations, mins and maxes as output.

If you want a dataset as output, either switch to proc summary or add the following:

proc means data=yourdata nway noprint;

class bmdecile cfdecile;

var RET VWRETD EWRETD;

output out=meandata mean=/autoname;

run;


Steve Denham

New Contributor
Posts: 4

Re: Cross sectional averages

stevedenham................

he wants avg of RET VWRETD EWRETD when BMDECILE=1 and CFDECILE=1 or

BMDECILE=2 and CFDECILE=2 or

.

.

.

BMDECILE=10 and CFDECILE=10

Respected Advisor
Posts: 2,655

Re: Cross sectional averages

I don't think so.  See: "For example: The average of RET VWRETD EWRETD when CFDECILE=1 and BMDECILE=5. Or the average of RET VWRETD EWRETD when CFDECILE=3 and BMDECILE=7. etc." in the original post.

He wants 10x10 = 100 means for each of three variables.  PROC MEANS or PROC SUMMARY is ideal for this.

Steve Denham

Contributor
Posts: 60

Re: Cross sectional averages

Quite right Steve. Thanks for the input everyone.

New Contributor
Posts: 4

Re: Cross sectional averages

this one is good compare to my previous code

data data1;

set data;

avg=mean(of RET VWRETD EWRETD);

where (BMDECILE=1 and CFDECILE=1) or (BMDECILE=2 and CFDECILE=2) or

(BMDECILE=3 and CFDECILE=3) or (BMDECILE=4 and CFDECILE=4) or

(BMDECILE=5 and CFDECILE=5) or (BMDECILE=6 and CFDECILE=6) or

(BMDECILE=7 and CFDECILE=7) or (BMDECILE=8 and CFDECILE=8) or

(BMDECILE=9 and CFDECILE=9) or (BMDECILE=10 and CFDECILE=10);

run;

Valued Guide
Posts: 765

Re: Cross sectional averages

hi ... given this problem statement ...

"I would approximately like to calculate 300 averages (100 for RET, 100 for VWETD, 100 for EWRETD). "

and ...

"when BMDECILE=1,2,3,4,5,6,7,8,9, 10   AND   CFDECILE=1,2,3,4,5,6,7,8,9,10. (ie: 10*10=100)."

I'm voting for Steve

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 419 views
  • 6 likes
  • 5 in conversation