BookmarkSubscribeRSS Feed
PrinceAde
Obsidian | Level 7
Please, I need help with the code below. 
I'm trying to create a table such that sex and aval are nested in the column, with n and pctn for sex, while for aval; sum and pct sum.
 
proc tabulate data=treatment2;
var aval;
class trt sex;
table trt all, (sex="gender(count)"*n=" " all*n=" " sex ="gender(%)"*pctn=" " all*pctn=" ") *
(aval="Lab_Group Result"*sum aval="Lab_Group Result"*pctn);
run;
When I ran this code it gave the following error;
 
ERROR: There are multiple statistics associated with a single table cell in the following nesting : TRT * SEX * N * AVAL * Sum.
ERROR: There are multiple statistics associated with a single table cell in the following nesting : TRT * SEX * N * AVAL * PctN. I'm using sas studio.
Thank you, anticipating replies.
3 REPLIES 3
ballardw
Super User

Some example data and what you expect the proc tabulate to show for that data would help.

 

You have that error because of this in your code:

 (sex="gender(count)"*n=" " all*n=" " sex ="gender(%)"*pctn=" " all*pctn=" ") *
(aval="Lab_Group Result"*sum aval="Lab_Group Result"*pctn

Where the * shows a nesting attempt you have STATISTICS N and PCTN in blue above attempting to  nest with SUM and PCTN shown in green below them inside the same column. You cannot nest a statistic or cross a statistic with another. Which means that you can't have statistics on both sides of an asterisk (nest) or a comma (row/column intersection).

 

Sometimes if you need complex tables you may need to do the summaries in other procedures and/or a data step and then use a different tool to prepare tables such as the Report Writing Interface in the data step that lets you place any value into cells of a table (caution: somewhat heavier programming involved)

 

 

 

PrinceAde
Obsidian | Level 7

I expect to have the sex(gender) and aval(lab_group result)to be nexted on the column, PS lab_group result = lgr, sum=S and pctn=P.

I expect the column to look like this;

 

 

gender(count)           gender(%)

F    M     All             F      M     All

lgr   lgr   lgr             lgr     lgr   lgr

S      S    S              P       P      P

ballardw
Super User

Input data in the form of data step code please.

 

And then show actual numbers based on that example data set. It doesn't have to be big, in fact probably shouldn't be more than 20 rows so you can calculate the numbers by hand and show where they go in the result. Your shown table has no place for the N of the Gender that you show in your code.

 

I have a fairly strong feeling that if you really want that appearance you will have to do a lot of preprocessing of your existing data set and possibly use a different reporting tool. The only way I know to get Tabulate to have different statistics in a column is to have them as ROW dimension expression crossing a class variable.

 

You may be able to get two different tables but they won't be side by side. Something like this:

proc tabulate data=sashelp.class;
   class sex age;
   var height ;
   table  n age* height*sum ,
         sex all
   ;
   table  pctn age* height*colpctsum,
         sex All
   ;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 580 views
  • 0 likes
  • 2 in conversation