Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Proc means Repetition

Status
Not open for further replies.

nirmalraj

MIS
Apr 20, 2005
33
0
0
US
Hi all,

I am getting multiple instances of same values when I use proc means to sum up by 2 variables , say gender and age but I am getting 4 age groups and same summed up value. I there a way to debug this.

Thanks,
Raj

********************************************************;
proc freq data = A noprint; tables participants*sex*age_r/ list missing nocol norow nopercent nocum out=X;run;

*****************************************************;
proc sort data = A; by participants age_r sex ;
proc means data = A n noprint sum;
by participants age_r sex ;
var g b;
output out= B(drop=_type_ _freq_)
sum(b)= b
sum(g)= a ;

proc print data=B;id sex ;var a b;run;

********************************************************;

proc sort data=X ;by sex age_r;
proc sort data=B;by sex age_r;

data age_sex; merge X(in=a ) B(in=b);
by sex age_r ;
*********************************************************;
proc print data=age_sex;id sex ; var age_r count a b;
*********************************************************;
 
Look up the proc means doco, and check out the "nway" option (under proc means statement). That should explain the issue. Basically, it'll be working out the results by different groupings of the "by" variable. (ie By participants + age_r, By Participants + Sex, By age_r + sex and by participants + age_r + sex). The _type_ variable can be used to determine what grouping is used. NWAY tells SAS to only use the full grouping.
Enjoy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top