Skip to content

Instantly share code, notes, and snippets.

@statgeek
Created June 4, 2014 15:17
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/6c885f6aea18dbd6caf8 to your computer and use it in GitHub Desktop.
Save statgeek/6c885f6aea18dbd6caf8 to your computer and use it in GitHub Desktop.
Create a format for ordinal numbers (1-1st, 2-2nd)
data ordinal_format;
length label $8.;
do number=1 to 300;
numstring = put(number, 16. -l);
if prxmatch('/(?<!1)1\s*$/',numstring) then ending='st';
else if prxmatch('/(?<!1)2\s*$/',numstring) then ending='nd';
else if prxmatch('/(?<!1)3\s*$/',numstring) then ending='rd';
else ending = 'th';
ordstring =catt(numstring, ending);
start=number;
label=ordstring;
fmtname="ordinal_fmt";
type="N";
output;
end;
keep start label fmtname type;
run;
proc format cntlin=ordinal_format;
run;
data want;
do i =1 to 100;
j=i;
output;
end;
format j ordinal_fmt.;
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment