BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bcoote
Fluorite | Level 6

Hello,

 

Is there a way to create a table displaying the frequencies of multiple variables compared to one variable using PROC FREQ? I'm using SAS 9.4. 

 

Best,

Brittany Coote

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The following code uses a data set you should have available. It does something similar to what you show but with out example input data it isn't obvious whether we need to sum something or are using counts. Run this and see if the results are at all like what you want.

proc tabulate data=sashelp.cars;
   class make ;
   class type;
   class origin;
  tables type origin,
         (all='All makes' make)*( colpctn n)
         ;
run;

There are options and things that can change things like row or column headings, formats of values shown. ODS style choices or overrides in the code can remove cell boundaries, change background/foreground colors, fonts and lots of stuff.

 

View solution in original post

9 REPLIES 9
Shmuel
Garnet | Level 18

Can you demostrate in a table what do you mean?

Please post a sample data and the frequency table you want to achive.

PaigeMiller
Diamond | Level 26

Do you mean?

 

proc freq data=have;
    tables x*y;
run;
--
Paige Miller
bcoote
Fluorite | Level 6

That is the format I am using, but I am trying to avoid having to do it for multiple variables. Is there a way to just compare multiple variables to one variable via frequencies?

art297
Opal | Level 21

Are you looking for something like?:

proc freq data=sashelp.class;
  tables sex*(age height weight);
run;

Art, CEO, AnalystFinder.com

 

 

aespinarey
Obsidian | Level 7

Is there a way to have an statement similar to this one come up with only one table rather than multiple tables? kind of like a demographics table comparing 2 different population (i.e. Smokers and Non Smokers). 

art297
Opal | Level 21

Yes there is, but post your question in a new thread as this one is already closed. Plus, in the new thread you post, include some sample data (in the form of a datastep), as well as what you want the output to look like.

 

Art, CEO, AnalystFinder.com

 

bcoote
Fluorite | Level 6

Hello,

 

This table illustrates what I would like to display. 

 

Thank you for your assistance. 

ballardw
Super User

The following code uses a data set you should have available. It does something similar to what you show but with out example input data it isn't obvious whether we need to sum something or are using counts. Run this and see if the results are at all like what you want.

proc tabulate data=sashelp.cars;
   class make ;
   class type;
   class origin;
  tables type origin,
         (all='All makes' make)*( colpctn n)
         ;
run;

There are options and things that can change things like row or column headings, formats of values shown. ODS style choices or overrides in the code can remove cell boundaries, change background/foreground colors, fonts and lots of stuff.

 

heatherjae15
Obsidian | Level 7

How do I get 2 variables and 1 column of frequency (called number of subjects) into a table?  Right now, I have the variables ID and  site and I need number of patients without the frequency heading.  

 

So the table would be

       ID      Site     number of patients (given by freqency)?

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 9 replies
  • 63438 views
  • 4 likes
  • 7 in conversation