Smky29
Smky29

Reputation: 13

How do I stack many frequency tables in SAS

I have a dataset of about 800 observations. I want to get the frequency of 14 variables. I want to get the frequency of these variable by shape (an example). There are 3 different shapes.

An example of doing this one time would obviously be: proc freq; tables color; by shape;run;

However, I do not want 42 frequency tables. I want one frequency table that has the list of 14 variables on the left side. The top heading will have shape1 shape2 shape3 with the frequencies of each variable underneath them. It would look like I transposed the data sets by percentage and then stacked them on top of each other.

I have several sets of combinations where I need to do this. I have about 5 different groups of variables and I need to make tables using 3 different by groups (necessitating about 15 tables). The first example I discussed is one example of such groups.

Any help would be appreciated!

Upvotes: 0

Views: 592

Answers (1)

Robert Soszyński
Robert Soszyński

Reputation: 1188

Using proc means and proc transpose. I give you some example. You can add more categories.

proc means data=sashelp.class nway n; 
    class sex age;
    output out=class(drop=_freq_ _type_) n=freq;
run;

proc transpose data=class out=class(drop=_name_) prefix=AGE;
    by sex;
    var freq;
    id age;
run;

data class_sum;
    set class;

    array a(*) age:;
    age_sum = sum(of age:);

    do i = 1 to dim(a);
        a(i) = a(i) / age_sum;
    end;
    drop i;
run;

Upvotes: 0

Related Questions