BookmarkSubscribeRSS Feed
dariatri
Calcite | Level 5
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!
4 REPLIES 4
Astounding
PROC Star

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.

dariatri
Calcite | Level 5
Ok, thanks!
Reeza
Super User

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!

 

dariatri
Calcite | Level 5
Thank you! Very close to what I was looking for.

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!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1389 views
  • 1 like
  • 3 in conversation