May 27, 2021 SAS
Cross-tableing involves using all possible combinations of two or more variables to produce a crosstabber also known as an occasional table. I n SAS, it is created using the PROC FREQ and CABLES options. F or example - if we need the frequency of each model in each model category, then we need to use the CABLES option of PROC FREQ.
The basic syntax for applying crosstaps in SAS is:
PROC FREQ DATA = dataset; TABLES variable_1*Variable_2;
The following is a description of the parameters used:
Consider the following from SASHELP. C ARS creates a dataset car1 that looks for the types of cars available under each car brand. I n this case, we need a single frequency value and a number of frequency values across types. W e can observe that the results show values across rows and columns.
PROC SQL; create table CARS1 as SELECT make,type,invoice,horsepower,length,weight FROM SASHELP.CARS WHERE make in ('Audi','BMW') ; RUN; proc FREQ data=CARS1 ; tables make*type; run;
When we execute the code above, we get the following results:
When we have three variables, we can group two of them and cross the list with the third variable. S o in the result we have two crosstases.
In the following example, we find the frequency of each type of car and the model of each model relative to the car. I n addition, we use the nocol and norow options to avoid and percentage values.
proc FREQ data=CARS2 ; tables make * (type model) / nocol norow nopercent; run;
When we execute the code above, we get the following results:
For 4 variables, the number of pairing combinations increases to 4. Each variable from Group 1 is paired with each variable in Group 2.
In the following example, we find the frequency of each model and the length of the car for each model. S imilarly, the horsepower frequency of each manufactured and per model.
proc FREQ data=CARS2 ; tables (make model) * (length horsepower) / nocol norow nopercent; run;
When we execute the code above, we get the following results: