Created
June 4, 2014 15:17
-
-
Save statgeek/6c885f6aea18dbd6caf8 to your computer and use it in GitHub Desktop.
Create a format for ordinal numbers (1-1st, 2-2nd)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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