```Date: Tue, 15 Aug 2000 09:59:01 -0700 Reply-To: Ya Huang Sender: "SAS(r) Discussion" From: Ya Huang Subject: Re: omit column in proc tabulate Comments: To: Bill Content-Type: text/plain; charset=us-ascii Bill, I like proc tabulate, but I usually would calculate statistics by myself and then use proc tabulate to put those numbers in the corresponding cells. In the following code, I used proc sql to do the calculation, you can also use proc summary + data step, or maybe pure data step programming to get the numbers. -------------------------------------------- data lefty; input campus \$ sex \$ hand \$ @@; cards; E M L E M R E M L E M R E F L E F L E F R E F L W M R W F R W M L W M L W M L W F R W F L ; proc sql; create table lefty as select distinct campus, count(*) as totn, sum(sex='M') as n_m, (calculated n_m)/(calculated totn)*100 as pct_m, sum(sex='F') as n_f, (calculated n_f)/(calculated totn)*100 as pct_f, sum(hand='L') as n_l, (calculated n_l)/(calculated totn)*100 as pct_l, 'Sex' as cat1, 'Hand' as cat2, 'M' as cat3, 'F' as cat4, 'L' as cat5 from lefty group by campus ; options nocenter formchar='|----|+|---'; proc tabulate; class campus cat1 cat2 cat3 cat4 cat5; var totn n_m pct_m n_f pct_f n_l pct_l; table campus, totn='Total'*sum=''*f=5. cat1=''*(cat3=''*(n_m='N'*f=4. pct_m='%'*f=5.1) cat4=''*(n_f='N'*f=4. pct_f='%'*f=5.1))*sum='' cat2=''*cat5=''*(n_l='N'*f=4. pct_l='%'*f=5.1)*sum='' / rts=10 ; run; --------------------------------------------- The SAS System 09:52 Tuesday, August 15, 2000 1 ------------------------------------------------- | | | Sex | Hand | | | |---------------------+----------| | | | M | F | L | | | |----------+----------+----------| | |Total| N | % | N | % | N | % | |--------+-----+----+-----+----+-----+----+-----| |campus | | | | | | | | |--------| | | | | | | | |E | 8| 4| 50.0| 4| 50.0| 5| 62.5| |--------+-----+----+-----+----+-----+----+-----| |W | 7| 4| 57.1| 3| 42.9| 4| 57.1| ------------------------------------------------- cat1-cat5 are some dummy category variable, used to make the table more like yours. Regards, Ya Huang Bill wrote: > > I would like to display some frequency data using proc tabulate, but > with a little twist. I'd like to concatenate class variables, and for > some of them, I'd like to omit the display of some levels without > omitting the entire observation. An example will make this clear: > > **how to show all males/females, but only the lefties in a tabulate > table; > data lefty; > infile cards missover; > input campus \$ > sex \$ > hand \$; > cards; > E M L > E M R > E M L > E M R > E F L > E F L > E F R > E F L > W M R > W F R > W M L > W M L > W M L > W F R > W F L > ; > proc tabulate; > class campus sex hand; > tables campus, all = 'Total' * F = 5.0 > (sex hand ) * > (n='N' * f = 5.0 pctn = '%' * f = > 5.1 )/rts=10; > run; > > produces: > ---------------------------------------------------------------- > | | | sex | hand | > | | |-----------------------+-----------------------| > | |Total| F | M | L | R | > | |-----+-----------+-----------+-----------+-----------| > | | N | N | % | N | % | N | % | N | % | > |--------+-----+-----+-----+-----+-----+-----+-----+-----+-----| > |campus | | | | | | | | | | > |--------| | | | | | | | | | > |E | 8| 4| 50.0| 4| 50.0| 5| 62.5| 3| 37.5| > |--------+-----+-----+-----+-----+-----+-----+-----+-----+-----| > |W | 7| 3| 42.9| 4| 57.1| 4| 57.1| 3| 42.9| > ---------------------------------------------------------------- > > I would like to keep the 15 subjects for some of the column variables > (in this case 'sex'), but eliminate some subjects for other column > variables (in this case the 6 right-handers), so that my table looks > like: > > ---------------------------------------------------- > | | | sex | hand | > | | |-----------------------+------------ > | |Total| F | M | L | > | |-----+-----------+-----------+-----------+ > | | N | N | % | N | % | N | % | > |--------+-----+-----+-----+-----+-----+-----+-----+ > |campus | | | | | | | | > |--------| | | | | | | | > |E | 8| 4| 50.0| 4| 50.0| 5| 62.5| > |--------+-----+-----+-----+-----+-----+-----+-----+ > |W | 7| 3| 42.9| 4| 57.1| 4| 57.1| > ---------------------------------------------------- > > All percents would be based on the total row N's of 8 and 7. > > Subsetting on the lefthanders, or deleting the 'R' values and using > the 'missing' option does not give me what I need. In the case of the > former, I'll lose 6 males and females, and in the case of the latter, > I'll have N and % columns for the missings, which is what I want to > supress. > > The extension of this would be to tack on more column variables, eg, > Race showing only the privileged, Religion showing only the chosen, > etc, while still being able to display all levels for all subjects in > other variables. > > TIA, > > Bill LeBlanc > Institutional Research > Valencia Community College > > ```

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