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)
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
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.