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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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