BookmarkSubscribeRSS Feed
Pre1
Calcite | Level 5

I have a dataset and I need to run a proc-freq cross-tabulation (two-way frequency table) of one variable by all variables in the dataset. 

 

Is there a way to do this without writing a step for each cross-tabulation? I have 70+ variables I need to run against sectorcollapsed. 

 

proc freq data=cath.characterlabels; 
    table sectorcollapsed*location;
run; 

I used a by-step, which didn't give me the output I needed, as it did tables separately for each category of the by variable (So I have 70*4 tables, which I do not want)

 

 

I would like the output of each variable to look exactly similar to what the tables code would give for each cross-tabulation with the following:

 Location1Location2Location3 Total
Sector1
Frequency
Percent
Row Pct
Col Pct
........  
Sector2     
Sector3     
      
      

(Count (n), Frequency(%), RowPct, ColPct, and then the total.

 

Any help would be greatly appreciated!

1 REPLY 1
ballardw
Super User

Simplest would be:

proc freq data=cath.characterlabels; 
    table sectorcollapsed* _all_;
run; 

That will procude sectorcollapsed with itself but the code is easy to make. Not difficult to get all of the variable names but that gets into macro language coding and adds a layer of complexity not needed.

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 582 views
  • 0 likes
  • 2 in conversation