<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: use proc format to convert a number to ordinal in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/use-proc-format-to-convert-a-number-to-ordinal/m-p/734901#M228948</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;... but I am trying to consolidate it into a single proc&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't know what this means.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the format created by the code does what it claims to do, why can't you just assign this format to the desired variables? Why wouldn't that be sufficient?&lt;/P&gt;</description>
    <pubDate>Sat, 17 Apr 2021 19:29:22 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-04-17T19:29:22Z</dc:date>
    <item>
      <title>use proc format to convert a number to ordinal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-format-to-convert-a-number-to-ordinal/m-p/734890#M228940</link>
      <description />
      <pubDate>Wed, 28 Apr 2021 19:54:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-format-to-convert-a-number-to-ordinal/m-p/734890#M228940</guid>
      <dc:creator>gleebglorb</dc:creator>
      <dc:date>2021-04-28T19:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: use proc format to convert a number to ordinal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-format-to-convert-a-number-to-ordinal/m-p/734901#M228948</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;... but I am trying to consolidate it into a single proc&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't know what this means.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the format created by the code does what it claims to do, why can't you just assign this format to the desired variables? Why wouldn't that be sufficient?&lt;/P&gt;</description>
      <pubDate>Sat, 17 Apr 2021 19:29:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-format-to-convert-a-number-to-ordinal/m-p/734901#M228948</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-17T19:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: use proc format to convert a number to ordinal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-format-to-convert-a-number-to-ordinal/m-p/734965#M228949</link>
      <description>&lt;P&gt;Not sure how one step is any better than two steps.&lt;/P&gt;
&lt;P&gt;Your code could be a lot simpler however.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ordinal_format;
  fmtname="ordinal_fmt";
  type="N";
  length label $10;
  do start=1 to 300;
    select(mod(start,10));
       when (1) label=cats(start,'st');
       when (2) label=cats(start,'nd');
       when (3) label=cats(start,'rd');
       otherwise label=cats(start,'th');
    end;
    output;
  end;
run;

proc format cntlin=ordinal_format;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Apr 2021 21:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-format-to-convert-a-number-to-ordinal/m-p/734965#M228949</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-17T21:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: use proc format to convert a number to ordinal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-proc-format-to-convert-a-number-to-ordinal/m-p/735062#M228972</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;What about 11, 12, 13, 111, 112, ....?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/370741"&gt;@gleebglorb&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Apr 2021 09:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-proc-format-to-convert-a-number-to-ordinal/m-p/735062#M228972</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-18T09:05:37Z</dc:date>
    </item>
  </channel>
</rss>

