Skip to content

Instantly share code, notes, and snippets.

@statgeek
Created February 28, 2018 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statgeek/0c4aeec9053cf8050be18a03b842c1b9 to your computer and use it in GitHub Desktop.
Save statgeek/0c4aeec9053cf8050be18a03b842c1b9 to your computer and use it in GitHub Desktop.
PROC FREQ - Cross Tab Table in a long format
/*This program is used when you want multiple m*n tables and you want it summarized. In this case the one variable, SEX is in the
KEEP statement, this will change depending on the variables in the code*/
ods output crosstabfreqs=summary;
proc freq data=sashelp.class;
table sex*(_all_);
run;
data long;
length variable $32. variable_value $50.;
set summary;
Variable=scan(table, 2, '*');
Variable_Value=strip(trim(vvaluex(variable)));
presentation=catt(frequency, " (", trim(put(percent/100, percent7.1)), ")");
keep sex variable variable_value frequency percent presentation;
label variable='Variable' variable_value='Variable Value';
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment