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

Dear all, 

 

I am using the following code to create a 'nice" output of frequencies and % for several variables: 

 

PROC TABULATE DATA=PATH.survey_formatted MISSING ORDER=FORMATTED;
TITLE6;
TITLE7 J=CENTER HEIGHT=2 COLOR=grey 'Table 1. Demographic Characteristics of Participants';
CLASS sex agecat racecat location education_level ;
CLASSLEV sex agecat racecat location education_level 
/ STYLE=[cellwidth=3in asis=on];
TABLES (sex agecat racecat location education_level)*
(n*F=4.0 pctn='(%)'*F=pctfmt.)/MISSTEXT='0' RTS=10;

 

The output, however, looks like one long horizontal table with 1 row and multiple columns. I would like it to look more like a table with many rows and 3 columns: variable name, Freq, % : 

 

---------| N     |    %   |

sex       |         |          |

   M      | 20    |  10% |

   F       | 180  | 90%  |

-------------------------

race       |

   White  |

   AA      |

   Asian  |

   Other  | 

 

How can it be done? Thank you very much. 

 

Julia

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Try

PROC TABULATE DATA=PATH.survey_formatted MISSING ORDER=FORMATTED;
   TITLE6;
   TITLE7 J=CENTER HEIGHT=2 COLOR=grey 'Table 1. Demographic Characteristics of Participants';
   CLASS sex agecat racecat location education_level ;
   CLASSLEV sex agecat racecat location education_level 
      / STYLE=[cellwidth=3in asis=on];
   TABLES sex agecat racecat location education_level,
          n*F=4.0 pctn='(%)'*F=pctfmt.
         /MISSTEXT='0' RTS=10;
run;

The tabulate tables statement uses a Comma to delineate page, row, column. If there is no comma then the request is treated as column; one comma means row then column, 2 commas the first is page, then row then column.

 

     tables page variables,

                row values,

                column values

                /

     ;

View solution in original post

2 REPLIES 2
ballardw
Super User

Try

PROC TABULATE DATA=PATH.survey_formatted MISSING ORDER=FORMATTED;
   TITLE6;
   TITLE7 J=CENTER HEIGHT=2 COLOR=grey 'Table 1. Demographic Characteristics of Participants';
   CLASS sex agecat racecat location education_level ;
   CLASSLEV sex agecat racecat location education_level 
      / STYLE=[cellwidth=3in asis=on];
   TABLES sex agecat racecat location education_level,
          n*F=4.0 pctn='(%)'*F=pctfmt.
         /MISSTEXT='0' RTS=10;
run;

The tabulate tables statement uses a Comma to delineate page, row, column. If there is no comma then the request is treated as column; one comma means row then column, 2 commas the first is page, then row then column.

 

     tables page variables,

                row values,

                column values

                /

     ;

braverju
Obsidian | Level 7
Thank you very much! It did the trick. I am sorry for not thanking you for a while. Just had to postpone this project and came back to it only today. Thank you again!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 2 replies
  • 4858 views
  • 1 like
  • 2 in conversation