<?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: Converting Roman numerals to numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/855983#M338243</link>
    <description>&lt;P&gt;What is the range of Roman numerals that you have to deal with?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would make a custom informat for the conversion. The example below assumes that your Roman numerals are all upper case.&lt;/P&gt;
&lt;PRE&gt;data forinformat;
   fmtname='Romantonumber';
   type='I';/* this means informat is made*/
   /* make the length of start the longest number
   of characters your roman numeral has
   */
   length start $ 10 ;
   /* set the largets numeric value you expect
      example uses 500
   */
   do label=1 to 500;
      /* use the Roman format to turn numeric 
         value into Roman numeral, use width
         of format, 10 in example to match
         length of start
      */
      start = strip(put(label,Roman10.));
      output;
   end;
run;
      
/* use the data set to create the informat*/
proc format cntlin=forinformat;
run;

/* use INPUT with values to create number*/
data example;
   input Roman $;
   number = input(roman,romantonumber.);
datalines;
I
II
V
VI
CCC
;&lt;/PRE&gt;
&lt;P&gt;If your Roman values are not upper case then use Input(upcase(roman),romantonumber.);&lt;/P&gt;</description>
    <pubDate>Fri, 27 Jan 2023 15:31:38 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-01-27T15:31:38Z</dc:date>
    <item>
      <title>Converting Roman numerals to numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/855975#M338241</link>
      <description>&lt;P&gt;Does anyone have a good way to convert Roman numerals to numbers? I have to do I-IX so I would like them to be 1-9 but I was just doing it with a format but what if it was more than 9?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 15:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/855975#M338241</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2023-01-27T15:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Roman numerals to numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/855980#M338242</link>
      <description>&lt;P&gt;Build yourself an informat:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data input;
  FMTNAME="myRoman";
  type="i";
  do _N_ = 1 to 9999;
    start=put(_N_,roman32.);
    label=put(_N_,best12.);
    output; 
  end;
  HLO="OU";
  label=".";
  output;
run;

proc format CNTLIN=input;
run;

data test;
  do _N_ = 10000, 1 to 9999;
    TEXTTXT=put(_N_,roman32.);
    TESTNUM=input(TEXTTXT,myRoman.);
    output; 
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 15:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/855980#M338242</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-01-27T15:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Roman numerals to numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/855983#M338243</link>
      <description>&lt;P&gt;What is the range of Roman numerals that you have to deal with?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would make a custom informat for the conversion. The example below assumes that your Roman numerals are all upper case.&lt;/P&gt;
&lt;PRE&gt;data forinformat;
   fmtname='Romantonumber';
   type='I';/* this means informat is made*/
   /* make the length of start the longest number
   of characters your roman numeral has
   */
   length start $ 10 ;
   /* set the largets numeric value you expect
      example uses 500
   */
   do label=1 to 500;
      /* use the Roman format to turn numeric 
         value into Roman numeral, use width
         of format, 10 in example to match
         length of start
      */
      start = strip(put(label,Roman10.));
      output;
   end;
run;
      
/* use the data set to create the informat*/
proc format cntlin=forinformat;
run;

/* use INPUT with values to create number*/
data example;
   input Roman $;
   number = input(roman,romantonumber.);
datalines;
I
II
V
VI
CCC
;&lt;/PRE&gt;
&lt;P&gt;If your Roman values are not upper case then use Input(upcase(roman),romantonumber.);&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 15:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/855983#M338243</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-27T15:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Roman numerals to numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/855988#M338245</link>
      <description>&lt;P&gt;They're actually at the end of inclusion/exclusion criteria. I see I-IX right now. It has 3 levels. For example, 4BI is 4 b i) and it could have ii) iii) etc. I wanted to build something flexible so it could work for a variety of different number of Roman numerals.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 15:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/855988#M338245</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2023-01-27T15:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Roman numerals to numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/855991#M338246</link>
      <description>&lt;PRE&gt;data example;&lt;BR /&gt;format ietestcd_std $200.;&lt;BR /&gt;input ietestcd_std &amp;amp;;&lt;BR /&gt;datalines;&lt;BR /&gt;Exclusion 4bi&lt;BR /&gt;Exclusion 2oi&lt;BR /&gt;Exclusion 2oix&lt;BR /&gt;Exclusion 4c&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;Here's some example data. I have to change these to EX04B1, EX02O1, EX02O9, EX04C. It doesn't seem likely that it would go past 9 but I don't know what's possible in a protocol. And depending which variable I use in the raw data, it can be all caps or like what I have presented. I guess for your solution, it will make more sense to use the version of the variable that's in all caps.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 15:52:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/855991#M338246</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2023-01-27T15:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Roman numerals to numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/856004#M338247</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181158"&gt;@tarheel13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;They're actually at the end of inclusion/exclusion criteria. I see I-IX right now. It has 3 levels. For example, 4BI is 4 b i) and it could have ii) iii) etc. I wanted to build something flexible so it could work for a variety of different number of Roman numerals.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you are going to have to provide a lot more rules and examples about when an "i" is a Roman numeral and when it is any other letter i . When you say 4B I have to assume that you have other values like 4A 4C (100) 4D (500).&lt;/P&gt;
&lt;P&gt;Extract you roman numeral then use one of the informats suggested and replace with the numeric value. TRANWRD might be possible. But not even going to guess without concrete examples.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please reread your original post in this thread and look for where there is a piece that the roman numerals are part of a longer text variable.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Does anyone have a good way to convert Roman numerals to numbers? I have to do I-IX so I would like them to be 1-9 but I was just doing it with a format but what if it was more than 9?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 27 Jan 2023 16:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/856004#M338247</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-27T16:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Roman numerals to numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/856011#M338248</link>
      <description>&lt;P&gt;I did not mention that it was part of a text variable. I was mostly looking for a flexible way to convert the Roman numerals rather than doing it one by one. I like to make something dynamic so it can handle all possible cases or as many as possible. I have written a macro that will work now using your informat. This is the way I am handling it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tarheel13_0-1674840129967.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79884i05241B6BF23072D4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tarheel13_0-1674840129967.png" alt="tarheel13_0-1674840129967.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 17:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/856011#M338248</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2023-01-27T17:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Roman numerals to numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/856023#M338252</link>
      <description>&lt;P&gt;hi, thanks so much. I love how short it is. I think this will work&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 17:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Roman-numerals-to-numbers/m-p/856023#M338252</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2023-01-27T17:15:42Z</dc:date>
    </item>
  </channel>
</rss>

