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
/
;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: