BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
spraynardz90
Calcite | Level 5

Hi

I am looking to calculate cross sectional averages.

Is this possible on sas?

I have attached a small sample of my data below.

1 ACCEPTED SOLUTION

Accepted Solutions
SteveDenham
Jade | Level 19

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

10 REPLIES 10
LinusH
Tourmaline | Level 20

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, CFDECILE;)

Data never sleeps
spraynardz90
Calcite | Level 5

Could you please be more specific?

LinusH
Tourmaline | Level 20

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
kevinmc
Calcite | Level 5

%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.

SteveDenham
Jade | Level 19

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

kevinmc
Calcite | Level 5

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

SteveDenham
Jade | Level 19

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

spraynardz90
Calcite | Level 5

Quite right Steve. Thanks for the input everyone.

kevinmc
Calcite | Level 5

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;

MikeZdeb
Rhodochrosite | Level 12

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

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 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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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