```Date: Wed, 13 Dec 2006 12:12:31 -0500 Reply-To: Gerhard Hellriegel Sender: "SAS(r) Discussion" From: Gerhard Hellriegel Subject: Re: NEED HELP ON OUTPUT You must think about the meaning of the operators! ',' is the trigger for the dimensions. Without ',' you'll have a 1-dim table, or a kind of "vector". With 1 ',' you have a 2-dim - table (matrix). 2 ',' = 3-dim-"cube" (the third dim is in fact realized by page-breaks between several tables). So with age,sex you'll get a 2-dim table with ages in rows and sex in columns. Something like M F 11 12 13 14 with a counter (default stat if you have no var of the var-list) in the white field. Now you decide to have other informations in the white field, eg. you want the averages of heights there instead of the counter. you use age,sex*height*mean In your report you want also see the average weights by sex and age, you use age,sex*height*mean sex*weight*mean That is much to write, so you can also use something like: age,sex*(height weight)*mean That says: sex is related to height and to weight (I only have to write it once) and also they have the same statistic. That is not necessary, they can also have different. Try age,sex*(height weight*mean) for height it is the default (sum). So let's think a moment, about: (age,sex)*height*mean What should that tell TABULATE? Maybe something like: age*height*mean,sex*height*mean ? One step back: assume you have a 1-dim table from age*height*mean (that works, try it!) and you have another one with sex*height*mean but you want to have them together. You could use age*height*mean sex*height*mean or write it shorter like: (age sex)*height*mean The layout is not what you want, because you get two tables side by side with fields, which have nothing to do with each other! (the age-fields contain several ages and the average height of the members of the age-groups. The SEX-part contain 2 fields with the average of height over sex! Now you decide to change the layout to bring that in a two dimensional table (something like age,sex). Not side-by side, but as 2-dim-table. What do you expect of that??? What result should be in that sex="F"/age=11 field? You don't HAVE that information! You have only the average of the age=11 group and the average of the sex="F" group. That (both, different) values must be in the field AGE=11/SEX="F" field! So you see, the blank seperator is something which does not change much in the contents of the fields. It fits tables together. The ,-operator has grouping-effects! You get new values, like "average of the heights in the group sex="F" with age=11" So the error message you'll get if you try something like age*height*mean,sex*height*mean ERROR: There are multiple analysis variables associated with a single table cell in the following nesting : Age * Height * Mean * Sex * Height * mean. ERROR: There are multiple statistics associated with a single table cell in the following nesting : Age * Height * Mean * Sex * Height * Mean. is missleading. You HAVE the same analysis variable (HEIGHT) and you HAVE the same statistic (MEAN), but you have 2 different views on the data which cannot fit together in a 2-dimensional table! Hope that clarifies a bit what the programmers of TABULATE thought by not allowing constructs with (a,b,c) Regards, Gerhard On Wed, 13 Dec 2006 07:44:27 -0800, rss wrote: >Peter Crawford wrote: >> On Tue, 12 Dec 2006 10:50:15 -0800, rss wrote: >> (in part ... the rest below >> >> > >> >but table age,sex*height does make sense! We're looking for the mean >> >height for males and females. >> > >> >> and >> >> >what's confusing is Table age,sex *(height weight) *mean does work. the >> >output is just what we're looking for. BUT Table(age,sex)*(height >> >weight) *mean does not work. What's the difference? >> >> You should probably be able to find this explained in the online doc >> or the book by Lauren Haworth, but herre does my slant on this >> challenge. >> >> the structure of a table statement is so flexible, it is a surprise >> sometimes to find this constraint >> >> Table (age,sex)*(height weight) *mean ; >> >> fails because there is a comma(,) within parentheses. >> >> What meaning or intention has >> Table (age,sex)* >> ?????????????????????????????????? >> >> Parentheses in "Table" support multiple items within a dimension >> sharing what is outside the parentheses. That is why (imho) you >> can't have a comma within the parentheses. Only 2 commas are >> allowed. The last is between the row definition and the column >> definition. It there are two commas, the the first separates >> page dimension definitions and row definitions. >> Wrapping a comma within parentheses implies more than one use of >> a comma. The table statement cannot cope nor understand that. >> >> >> Peter Crawford >> >> >> On Tue, 12 Dec 2006 10:50:15 -0800, rss wrote: >> >Gerhard Hellriegel wrote: >> >> Sorry, I didn't read your question in full: >> >> that rearranging or relating of items is not always possible. The >> >> ','-operator is the seperator for the dimensions. If you have 1 ',', you >> >> have a real table (2 dimensions), if you have 2 ',' it is a 3- >> dimensional >> >> table (the third dimension is realized via kind of page-breaks between). >> >> >> >> If you have a blank - operator, you simply add new columns if it is in >> the >> >> column-dimension, or rows, if it is in the row dimension. One can >> simply say >> >> "you put together some tables". With the '*' operator you build >> subgroups or >> >> select a statistic. That operators can be used together with (), because >> >> they can relate to one other item, or more than one. For the dimension >> >> separator ',' that is senseless. What should that mean, e.g. >> >> >> >> (age,sex)*height*mean; ?? >> >> >> >> AGE and SEX are class-variables, you cannot relate them to a statistic! >> >> (What's the mean-sex?). >> >> >> >> Also a table statement like: >> >> >> >> age*mean all='average', sex *height weight *mean='' >> >> >> >> Is not ok, because you assign different statistics (ok, the same in that >> >> case, but could be also *sum or something else) to one singe cell. Not >> allowed! >> >> >> >> >> >> >> >> >> > >> > >> > >> > >> >but table age,sex*height does make sense! We're looking for the mean >> >height for males and females. >> > >> >what's confusing is Table age,sex *(height weight) *mean does work. the >> >output is just what we're looking for. BUT Table(age,sex)*(height >> >weight) *mean does not work. What's the difference? >> >> On Tue, 12 Dec 2006 12:06:14 -0500, Gerhard Hellriegel >> >> wrote: >> >> >> >> >For sure you are right: the means can (and should) change if there are >> more >> >> >than one candidate in a group. That should have influence to the >> column - >> >> >average, because if there are 10 with weight 100 and 1 with weight 50 >> then >> >> >it has to go closer to 100. >> >> >The ( ) have the purpose (similar to mathematic formulas) to change >> >> >relations. Eg. the statement like you have as example relates sex to >> height >> >> >*AND* to weight. If you write it like >> >> > >> >> > >> >> >proc tabulate data=sashelp.class; >> >> > >> >> >class age sex; var height weight ; >> >> > >> >> >table age all='average', sex *height weight *mean='' ; >> >> > >> >> >run; >> >> > >> >> >sex is only related to height, not to weight! So you get 2 columns for >> the >> >> >heights of F and M, but only 1 column for WEIGHT, which means "average >> >> >WEIGHT independant of SEX". >> >> > >> >> >Regards, >> >> >Gerhard >> >> > >> >> > >> >> >On Tue, 12 Dec 2006 08:10:11 -0800, rss wrote: >> >> > >> >> >>so close. Ok, after a little experimenting I got the following: >> >> >> >> >> >>proc tabulate data=sashelp.class; >> >> >> >> >> >> class age sex; >> >> >> var height weight ; >> >> >> >> >> >> >> >> >> table age all='average', sex *(height weight ) *mean='' ; >> >> >> >> >> >> >> >> >> run; >> >> >>now this produces the output so it looks correctly bit the averages it >> >> >>prints out are calculated incorrectly!!!! What in the world is going >> >> >>on? When I try *sum it seems to be working. Oh, this must be because >> >> >>for different ages we have a different number of observations, so we >> >> >>can't just take the average of what we see. >> >> >> >> >> >> >> >> >>Is thee some logic (there almost always is) as to when you use () and >> >> >>when you don't? >> >> >> >> >> >>as noted above: >> >> >> >> >> >>Table (x,y) doesn't work but table (x *y) does and so does table x,y >> *z > > >Peter, > >Thanks for your help. > >Please try to explain this: > >table age,sex*(height weight) *mean; this works, but > >table (age,sex)*(height weight) *mean; this does not work. You say >you can only have two commas but here I only have 1. > >It seems in the first case we would be applying the *(height weight) to >jest sex and that makes sense but in the second case we are applying >*(height weight) to (age,sex) and that for some reason doesn't make >sense. Lastly, I thought there were examples of tabulate using 3 >commas. ```

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