Date: Tue, 16 Feb 1999 20:31:03 +0000
Reply-To: Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Subject: Re: proc freq/tablulate ?
In-Reply-To: <919188556.2111734.0@vm121.akh-wien.ac.at>
Content-Type: text/plain; charset=iso-8859-1
In article <919188556.2111734.0@vm121.akh-wien.ac.at>, Lydia Pettis
<lp14@CORNELL.EDU> writes
>I have a simple set of observations with these variables: key, location
>(preset options), itemnum (numeric for SUM) and fmt (2 choices);
>
>BIBKEY LOCATION ITEMNUM FMT
>
>AAA2148 LAW 1 S
>AAA2149 LAW 1 B
>AAA2149 WASON 1 B
>AAA2150 VET 1 B
>AAA2150 MANN 6 B
>AAA2150 MANN 2 B
>AAA2151 FINE ARTS 1 B
>AAA2152 FINE ARTS 1 S
>AAA2153 FINE ARTS 1 S
>AAA2153 OLIN 1 B
>AAA2154 MATH 7 B
>
>I am familiar with both proc freq and proc tabulate, but I realize what I
>need is a combination of the two. Specifically, I need a table which sums
>the analysis variable ITEMNUM by CLASS vars LOCATION and FMT (I can do this
>with tabulate) AND that can be ORDERED by the FREQUENCY of the ITEMNUM SUM.
>When I use ORDER=FREQ it orders by the the number of 'hits' per location,
>not the sum of ITEMNUM.
>
>So, in the example above, the ORDER=FREQ option puts Fine Arts first
>because there are 3 observations, and Mann second with 2 observations. What
>I want to see is Mann, with the highest ITEMNUM (6+2=8) first in the list,
>followed by Math with ITEMNUM=7. I would also like to see percents by row
>and column and 'all', as can be done with FREQ.
>
>Is there any hope for me?
>
>Thanks for your help.
>
>Lydia
>
>
>
>*********************************************************
>Lydia Pettis 255-9477
>Applications Programmer/Analyst III
>Library Technology Department
>501 Olin Library
>Cornell University lp14@cornell.edu
>*********************************************************
Display this in font sasfont, and the lines become OK
SAS-L 19:53 Tuesday, February 16, 1999
Crawford Software Consultancy
Location /FMT N PCTN
MANN ALL 8 34.8
B 8 34.8
MATH ALL 7 30.4
B 7 30.4
FINE ARTS ALL 3 13.0
B 1 4.3
S 2 8.7
LAW ALL 2 8.7
B 1 4.3
S 1 4.3
WASON ALL 1 4.3
B 1 4.3
VET ALL 1 4.3
B 1 4.3
OLIN ALL 1 4.3
B 1 4.3
ALL 23 100.0
Here the main class group LOCATION is ordered by its frequency.
Was that what you wanted ?
Instead of treating ITEMNUM as an analysis variable, put it into the
FREQ statement, like:
proc tabulate missing format=best8. order=freq;
freq itemnum;
class location fmt;
table (location=' ' *(all fmt=' ' ) all), n pctn*f=5.1
/rts=25 box='Location /FMT';
run;
But you wanted a cross tab ?
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
SAS-L 19:53 Tuesday, February 16, 1999 2
Crawford Software Consultancy
FMT
ALL B S
n % n % n %
LOCATION
MANN 8 34.8 8 34.8 . .
MATH 7 30.4 7 30.4 . .
FINE ARTS 3 13.0 1 4.3 2 8.7
LAW 2 8.7 1 4.3 1 4.3
WASON 1 4.3 1 4.3 . .
VET 1 4.3 1 4.3 . .
OLIN 1 4.3 1 4.3 . .
ALL 23 100.0 20 87.0 3 13.0
shows each cell as a % of the 23 total, using table statement
table (location all),(all fmt ) *( n='n' pctn='%'*f=5.1 ) /rts=25 ;
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
To show the alternative % across and down as well as overall
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
SAS-L 19:53 Tuesday, February 16, 1999 3
Crawford Software Consultancy
FMT
ALL B S
n n all % loc % fmt % n all % loc % fmt %
LOCATION
MANN 8 8 34.8 40.0 100.0 . . . .
MATH 7 7 30.4 35.0 100.0 . . . .
FINE ARTS 3 1 4.3 5.0 33.3 2 8.7 66.7 66.7
LAW 2 1 4.3 5.0 50.0 1 4.3 33.3 50.0
WASON 1 1 4.3 5.0 100.0 . . . .
VET 1 1 4.3 5.0 100.0 . . . .
OLIN 1 1 4.3 5.0 100.0 . . . .
ALL 23 20 87.0 100.0 87.0 3 13.0 100.0 13.0
this used the, more complex table statement:
table (location all),(all*n='n' fmt*( n='n'
pctn ='all %'*f=5.1
pctn<location all>='loc %'*f=5.1
pctn<fmt all>='fmt %'*f=5.1 )
) /rts=12 ;
You have to pick the combinations you need
--
Peter Crawford