You can only do this partially. You would have to use both VAR1 and VAR2 as class variables, and nest them:
var1 * var2
The values of VAR2 would need to be constant for all VAR1=A observations. That constant value would be the only subcategory available when VAR1=A.
If you do it by VAR2 as the sub variable, you can keep it constant for group A and then it'll show as desired, though you'll still have an entry. I set it to missing and added a format to have it show up as a space. If this doesn't meet your expectations please post details of what you're looking for and what you're started with.
*sort data;
proc sort data=sashelp.class out=class;
by sex age;
run;
*create sublevels with age missing for female;
data class_demo;
set class;
if sex='F' then
age=.;
run;
*format to display missing as a space;
proc format;
value age_fmt low-high=[8.] .=' ';
run;
*Tabulate example;
proc tabulate data=class_demo;
class sex age / missing;
table sex*age, N=Count / misstext='';
format age age_fmt.;
run;
@dariatri wrote:
Using proc tabulate, I want to create a frequency distribution table (n, %) of a char variable "var1" (which gets 'A' or 'B'). However, 'B' value can be further subdivided by another variable, let's say "var2" (which gets 'b1' or 'b2'). How can I get a table that shows the frequency distribution of 'A' (with no subdivisions) and 'B' (subdivided by var2) all in one table.
Thanks!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.