@Tom What about 11, 12, 13, 111, 112, ....?
@gleebglorb
Below a solution approach using a function in a format. If you want to then you can store both user defined functions and formats in a permanent location and you would need to run this bit of the code only ad-hoc if you need to change something.
proc fcmp outlib=sasuser.funcs.nominal;
function nominal(in_num) $;
length out_str temp $10;
temp=left(put(in_num,10.));
if missing(temp) then out_str=' ';
else
if substrn(temp,lengthn(temp)-1) in ('11','12','13') then
do;
out_str=cats(temp,'th');
end;
else
do;
select(mod(in_num,10));
when (1) out_str=cats(temp,'st');
when (2) out_str=cats(temp,'nd');
when (3) out_str=cats(temp,'rd');
otherwise out_str=cats(temp,'th');
end;
end;
return(out_str);
endsub;
run;quit;
options cmplib=sasuser.funcs;
proc format;
value nominal(default=10)
other=[nominal()]
;
run;
data have;
do num_var=1 to 25, 99 to 125, 999 to 1025;
output;
end;
stop;
run;
proc print data=have;
format num_var nominal10.;
run;
... View more