Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@statgeek
Created December 15, 2021 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save statgeek/c91ec43ce4f0ef24c440c95465611123 to your computer and use it in GitHub Desktop.
Save statgeek/c91ec43ce4f0ef24c440c95465611123 to your computer and use it in GitHub Desktop.
Create an Other Category automatically within PROC FREQ
/*This is an example of how to create an Other category for everything except the top 3*/
*not ideal, other becomes first format - will look into how to make it last value;
*get counts;
proc freq data=sashelp.class order = freq;
table age / out=counts;
run;
*create format;
data counts_fmt;
set counts (OBS=3) end=eof;
*length label $10.;
fmtname = 'Age_fmt';
start = age;
label = age;
output;
if eof then do;
hlo = 'O';
label = 'Other';
output;
end;
run;
proc format cntlin=counts_fmt;
run;
*test applied format;
proc freq data=sashelp.class;
table age;
format age age_fmt.;
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment