<?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: how to read numbers of the form '00000-34.56' ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106356#M22173</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you can't input them directly as numeric if the - sign is in the middle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read as character and then do a clever use of substr/if or PRX and use input on the produced substring to create a new numeric variable of the desired format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input var1 $12.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format var2 best12.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var2=input(prxchange("s/(0*\.?)(-?\[0-9.]\d*)/$2/",1,var1), 8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;0000.-34.56&lt;/P&gt;&lt;P&gt;00000-34.56&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since regular expressions are not of common knowledge, I'll explain what this prxchange does that could be replicated with a mix of substrings/if conditions with some text functions&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;s indicates that PRX can/will do a substitution (hence prxchange and not prxmatch)&lt;/P&gt;&lt;P&gt;the 3 /// are actual regular expression delimiters. The first two delimitate start/end of the expression that is to be matched. The last 2 delimitate the substitution.&lt;/P&gt;&lt;P&gt;()() delimiter 2 distinct capturing groups that can be refererenced by $1$2 respectively in the substitution segment&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(0*\.?)&lt;/P&gt;&lt;P&gt;captures as many 0s as possible at the start of the string, (zero or more 0s), the \.? captures 0 or 1 periods. The \ is used because . is a regex construct and needs to be escaped to represent the period character itself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(-?\[0-9.]\d*)&lt;/P&gt;&lt;P&gt;-? captures 0 or one hyphen (or negative sign). [] represent a group of character, in this case, 0-9 as well as period within the group. Inside the group, the period does not need to be escaped with a backslash. There are no quantifiers constructs following the [] meaning it will match exactly one of these characters. \d represents any "digits" characters (effectively 0-9 period and possibly hyphen, I can't remember) * means match as many as possible of those digits characters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the $2 means that the value returned by the prxchange function will be that of the 2nd capturing group in the regular expression, in this case (-?\[0-9.]\d*) which is then input as a 8. number. I've used format best12. statement as this is the default SAS number format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 09 Aug 2013 12:01:27 GMT</pubDate>
    <dc:creator>Vince28_Statcan</dc:creator>
    <dc:date>2013-08-09T12:01:27Z</dc:date>
    <item>
      <title>how to read numbers of the form '00000-34.56' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106352#M22169</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What informat should I use to read in these numbers? The number in the example is -34.56.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Joe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 09:29:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106352#M22169</guid>
      <dc:creator>mediaeval</dc:creator>
      <dc:date>2013-08-09T09:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to read numbers of the form '00000-34.56' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106353#M22170</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;INFORMAT 6.2 you can apply...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 10:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106353#M22170</guid>
      <dc:creator>UrvishShah</dc:creator>
      <dc:date>2013-08-09T10:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to read numbers of the form '00000-34.56' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106354#M22171</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When I run the data step,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data negs;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set maindata;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat premium 11.2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; newpremium = Put(premium,11.2);&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It generates the error, "Invalid numeric data '0000.-34.56' at line..." for the record in question. &lt;/P&gt;&lt;P&gt;The number is in a string, 11 characters in length, hence the "11.2"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 10:46:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106354#M22171</guid>
      <dc:creator>mediaeval</dc:creator>
      <dc:date>2013-08-09T10:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to read numbers of the form '00000-34.56' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106355#M22172</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please tell us more about the form.&lt;/P&gt;&lt;P&gt;Is always a negative number? If not, what does that look like then?&lt;/P&gt;&lt;P&gt;Is the number always prefixed with a constant of 00000? If not, which other appearances is there?&lt;/P&gt;&lt;P&gt;It seems that some kind of string manipulation is needed, such substr() and/or scan().&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 12:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106355#M22172</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-08-09T12:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to read numbers of the form '00000-34.56' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106356#M22173</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you can't input them directly as numeric if the - sign is in the middle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read as character and then do a clever use of substr/if or PRX and use input on the produced substring to create a new numeric variable of the desired format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input var1 $12.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format var2 best12.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var2=input(prxchange("s/(0*\.?)(-?\[0-9.]\d*)/$2/",1,var1), 8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;0000.-34.56&lt;/P&gt;&lt;P&gt;00000-34.56&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since regular expressions are not of common knowledge, I'll explain what this prxchange does that could be replicated with a mix of substrings/if conditions with some text functions&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;s indicates that PRX can/will do a substitution (hence prxchange and not prxmatch)&lt;/P&gt;&lt;P&gt;the 3 /// are actual regular expression delimiters. The first two delimitate start/end of the expression that is to be matched. The last 2 delimitate the substitution.&lt;/P&gt;&lt;P&gt;()() delimiter 2 distinct capturing groups that can be refererenced by $1$2 respectively in the substitution segment&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(0*\.?)&lt;/P&gt;&lt;P&gt;captures as many 0s as possible at the start of the string, (zero or more 0s), the \.? captures 0 or 1 periods. The \ is used because . is a regex construct and needs to be escaped to represent the period character itself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(-?\[0-9.]\d*)&lt;/P&gt;&lt;P&gt;-? captures 0 or one hyphen (or negative sign). [] represent a group of character, in this case, 0-9 as well as period within the group. Inside the group, the period does not need to be escaped with a backslash. There are no quantifiers constructs following the [] meaning it will match exactly one of these characters. \d represents any "digits" characters (effectively 0-9 period and possibly hyphen, I can't remember) * means match as many as possible of those digits characters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the $2 means that the value returned by the prxchange function will be that of the 2nd capturing group in the regular expression, in this case (-?\[0-9.]\d*) which is then input as a 8. number. I've used format best12. statement as this is the default SAS number format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 12:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106356#M22173</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-08-09T12:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to read numbers of the form '00000-34.56' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106357#M22174</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all. The input field is 11 characters long, with two decimal places. Some sample data:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;00000000.00&lt;/P&gt;&lt;P&gt;00000142.31&lt;/P&gt;&lt;P&gt;00000-23.86&lt;/P&gt;&lt;P&gt;00005238.99&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that for positive numbers, the plus sign is not there. If the minus sign were not appearing, with leading zeroes, the informat would simply be 11.2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 12:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106357#M22174</guid>
      <dc:creator>mediaeval</dc:creator>
      <dc:date>2013-08-09T12:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to read numbers of the form '00000-34.56' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106358#M22175</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The PRX solution I posted will actually read 00005238.99 appropriately as well. All of the above work. If you want to test it against your entire dataset and find anomalies/different ways that your numbers are written, I can modify the PRX for you if it's a one-time job.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An alternative since there appears to be no case of 0000.dd.dd in your data (period twice) without PRX would be as follow:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input var1 $11.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format var2 best12.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var2=input(substr(var1, (findc(var1, "123456789.-")), 12-(findc(var1, "123456789.-"))),8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;00000000.00&lt;/P&gt;&lt;P&gt;00000142.31&lt;/P&gt;&lt;P&gt;00000-23.86&lt;/P&gt;&lt;P&gt;00005238.99&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 13:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106358#M22175</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-08-09T13:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to read numbers of the form '00000-34.56' ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106359#M22176</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In code SAS would be happy to resolve 00000-23.86 as (00000 - 23.86).&lt;/P&gt;&lt;P&gt;So here is one trick using RESOLVE() function to call %SYSEVALF() for every value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; input var1 $11.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; format var2 best12.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; var2=input(resolve('%sysevalf('||var1||')'),11.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; put var1= var2=;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;00000000.00&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;00000142.31&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;00000-23.86&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;00005238.99&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;var1=00000000.00 var2=0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;var1=00000142.31 var2=142.31&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;var1=00000-23.86 var2=-23.86&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;var1=00005238.99 var2=5238.99&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 13:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-numbers-of-the-form-00000-34-56/m-p/106359#M22176</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-08-09T13:52:17Z</dc:date>
    </item>
  </channel>
</rss>

