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
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
/
;
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
/
;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.