LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 2 Aug 2006 08:48:46 -0400
Reply-To:     Jonas Bilenas <jonas.bilenas@CHASE.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jonas Bilenas <jonas.bilenas@CHASE.COM>
Subject:      Re: proc means format

I see you wanted stats on another variable. Here is example to report mean incomes and output:

PROC TABULATE data=test noseps formchar=' '; CLASS year month sex/preloadfmt order=data; var income; format sex $sex.; KEYLABEL n=' ' sum=' ' mean=' ' pctn=' ' pctsum=' '; TABLE year*(month all) , (sex all) *(n*f=comma6. income='Mean Income'*mean*f=dollar10.2 ) / rts=20 row=float misstext=' '; run;

OUTPUT:

sex

Male Female All

Mean Mean Mean Income Income Income

year month 2004 1 6 $50,884.99 4 $51,039.57 10 $50,946.82 2 1 $56,671.17 1 $56,671.17 3 1 $49,702.95 1 $49,702.95 6 1 $58,921.01 1 $58,921.01 11 1 $45,028.99 1 $45,028.99 All 8 $51,460.51 6 $51,351.38 14 $51,413.74 2005 month 1 2 $58,491.26 2 $58,491.26 All 2 $58,491.26 2 $58,491.26 2006 month 1 3 $44,351.55 3 $44,351.55 3 1 $50,536.82 1 $50,536.82 All 4 $45,897.87 4 $45,897.87

On Wed, 2 Aug 2006 08:33:50 -0400, Jonas Bilenas <jonas.bilenas@CHASE.COM> wrote:

>On Wed, 2 Aug 2006 00:56:27 -0700, skyline <carf4F@GMAIL.COM> wrote: > >>Hello, >> >>Suppose I want to compupte the mean of income for each year, each month >>and each sex. I can get the value by >> >>proc means data=test; >>by year month sex; >>run; >> >>But I would like to have output formatted as >> >>year month male female >>2006 1 (some number) (some number) >>2006 2 (some number) (some numebr) >> >>how should I choose the options of proc means? >> >>Thank you, > >Try the handy PROC TABULATE. Here is sample data and code and Output: > >options nocenter symbolgen mprint fullstimer; > >data test; >input year month sex $; >datalines; >2004 1 M >2004 1 F >2004 1 M >2004 1 F >2005 1 M >2004 1 F >2004 2 M >2006 1 F >2004 1 M >2006 3 F >2004 1 M >2004 6 F >2004 1 M >2004 11 F >2005 1 M >2004 1 F >2004 1 M >2006 1 F >2004 3 M >2006 1 F >;; >run; > >proc format; > value $sex 'M' = 'Male' > 'F' = 'Female' > ; >run; >PROC TABULATE data=test noseps formchar=' '; > CLASS year month sex; > format sex $sex.; > KEYLABEL n=' ' sum=' ' mean=' ' pctn=' ' pctsum=' '; > TABLE year*month > , > sex > *(n*f=comma6.) > / rts=20 row=float misstext=' '; >run; > > >OUTPUT: > > >The SAS >System > 08:20 Wednesday, August 2, 2006 2 > > > sex > > Female Male > > year month > 2004 1 4 6 > 2 1 > 3 1 > 6 1 > 11 1 > 2005 1 2 > 2006 1 3 > 3 1 > > >Oh, if you want Males before Females: > >proc format; > value $sex (notsorted) > 'M' = 'Male' > 'F' = 'Female' > ; >run; >PROC TABULATE data=test noseps formchar=' '; > CLASS year month sex/preloadfmt order=data; > format sex $sex.; > KEYLABEL n=' ' sum=' ' mean=' ' pctn=' ' pctsum=' '; > TABLE year*month > , > sex > *(n*f=comma6.) > / rts=20 row=float misstext=' '; >run; > >output: > sex > > Male Female > > year month > 2004 1 6 4 > 2 1 > 3 1 > 6 1 > 11 1 > 2005 1 2 > 2006 1 3 > 3 1 > > >You want soem totals, try the ALL statement here and there: > > >PROC TABULATE data=test noseps formchar=' '; > CLASS year month sex/preloadfmt order=data; > format sex $sex.; > KEYLABEL n=' ' sum=' ' mean=' ' pctn=' ' pctsum=' '; > TABLE year*(month all) > , > sex all > *(n*f=comma6.) > / rts=20 row=float misstext=' '; >run; > >OUTPUT: > > sex > > Male Female All > > year month > 2004 1 6.00 4.00 10 > 2 1.00 1 > 3 1.00 1 > 6 1.00 1 > 11 1.00 1 > All 8.00 6.00 14 > 2005 month > 1 2.00 2 > All 2.00 2 > 2006 month > 1 3.00 3 > 3 1.00 1 > All 4.00 4 > > >Isn't TABULATE great? > >Jonas Bilenas >Decision Science >JP Morgan Chase >Wilmington DE


Back to: Top of message | Previous page | Main SAS-L page