<?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: Pattern checking for decimal numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721188#M223481</link>
    <description>&lt;P&gt;Regular expressions are for strings, not numbers.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you mean to create your original COL1 variable as a character string?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input col1 $40. ;
datalines;
0.01238788
61.15612
123.12
12.1244
12345.125665
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What do you think the regular expression you have means?&lt;/P&gt;
&lt;PRE&gt;^[0-9]\d{1,20}(\.\d{1,10})?%?$&lt;/PRE&gt;
&lt;P&gt;What does DECIMAL20.5 mean? Is that like the SAS format 20.5 which means 20 character long with the last 6 being the decimal point and 5 digits to the right of the decimal point?&lt;/P&gt;</description>
    <pubDate>Tue, 23 Feb 2021 05:09:37 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-02-23T05:09:37Z</dc:date>
    <item>
      <title>Pattern checking for decimal numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721185#M223479</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;I have a business problem where I wanted to perform patter check on the column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted to check if the values are in a particular format like decimal20.5. It should fail if the format is different from it.&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input col1;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;0.01238788&lt;/P&gt;&lt;P&gt;61.15612&lt;/P&gt;&lt;P&gt;123.12&lt;/P&gt;&lt;P&gt;12.1244&lt;/P&gt;&lt;P&gt;12345.125665&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- &amp;gt; using below solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let pattern=^[0-9]\d{1,20}(\.\d{1,10})?%?$;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;pattern_val=pxparse("/&amp;amp;pattern./");&lt;/P&gt;&lt;P&gt;v1=prxmatch(%nrbquote(pattern_val),col1);&lt;/P&gt;&lt;P&gt;if prxmatch(%nrbquote(pattern),col1) gt 0 then pass=0;&lt;/P&gt;&lt;P&gt;else pass=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;0- means the value is in decimal 20.5 format&lt;/P&gt;&lt;P&gt;1- other than that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note:&lt;/P&gt;&lt;P&gt;I am not much familiar with regex and took the expression from internet.&lt;/P&gt;&lt;P&gt;I have to use the snippet in my other macro codes so need to make it dynamic with pattern code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is very much appreciated.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 05:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721185#M223479</guid>
      <dc:creator>msr1</dc:creator>
      <dc:date>2021-02-23T05:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern checking for decimal numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721187#M223480</link>
      <description>&lt;P&gt;No too sure why you use macro functions.&lt;/P&gt;
&lt;P&gt;Also note that [0-9] is the same as \d&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is simpler:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let pattern=^\d{1,20}(\.\d{1,10})?%?$;
data WANT;
  set HAVE;
  PASS = prxmatch("/&amp;amp;pattern/",strip(COL1)) &amp;gt; 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What doesn't work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lastly,&amp;nbsp; &amp;nbsp;&lt;U&gt;&lt;STRONG&gt;Use the appropriate icon to paste your SAS code.&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 05:05:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721187#M223480</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-02-23T05:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern checking for decimal numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721188#M223481</link>
      <description>&lt;P&gt;Regular expressions are for strings, not numbers.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you mean to create your original COL1 variable as a character string?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input col1 $40. ;
datalines;
0.01238788
61.15612
123.12
12.1244
12345.125665
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What do you think the regular expression you have means?&lt;/P&gt;
&lt;PRE&gt;^[0-9]\d{1,20}(\.\d{1,10})?%?$&lt;/PRE&gt;
&lt;P&gt;What does DECIMAL20.5 mean? Is that like the SAS format 20.5 which means 20 character long with the last 6 being the decimal point and 5 digits to the right of the decimal point?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 05:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721188#M223481</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-23T05:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern checking for decimal numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721190#M223482</link>
      <description>&lt;P&gt;If all you are wanting to do is flag values with values upto 5 decimal places, then below should suffice?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, the DATA step with PRX functions have errors (example pattern_val is listed as pattern in the IF statements).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input col1;
	decimal = length(scan(strip(put(col1,best20.)),2,"."));

	if decimal &amp;gt;= 5 then
		pass = 1;
	else pass=0;
	drop decimal;
	datalines;
0.01238788
61.15612
123.12
12.1244
12345.125665
;
run;

/* Do not need the below */
%let pattern=^[0-9]\d{1,20}(\.\d{1,10})?%?$;

data want;
	set have;
	pattern_val=prxparse("/&amp;amp;pattern./");
	v1=prxmatch(%nrbquote(pattern_val),col1);

	if prxmatch(%nrbquote(pattern_val),col1) gt 0 then
		pass=0;
	else pass=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Feb 2021 05:20:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721190#M223482</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-02-23T05:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern checking for decimal numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721194#M223484</link>
      <description>Yes it is format 20.5 with 5 digits after decimal.&lt;BR /&gt;I am not sure about the regex, I took it from the internet.&lt;BR /&gt;My concern is, I need to perform validation on my data, and need to verify it all the values are in format 20.5, anything apart from that will fail.&lt;BR /&gt;Its not on one table, have to do it for multiple table</description>
      <pubDate>Tue, 23 Feb 2021 05:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721194#M223484</guid>
      <dc:creator>msr1</dc:creator>
      <dc:date>2021-02-23T05:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern checking for decimal numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721195#M223485</link>
      <description>its not about flagging with values upto 5 decimal places,&lt;BR /&gt;will have to apply the query to teradata in order to validate the values, Some tabla can have other format as well, like decimal30.5 decimal 20.3 etc ,WIll tweak it accordingly.&lt;BR /&gt;Thanks</description>
      <pubDate>Tue, 23 Feb 2021 05:44:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721195#M223485</guid>
      <dc:creator>msr1</dc:creator>
      <dc:date>2021-02-23T05:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern checking for decimal numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721196#M223486</link>
      <description>&lt;P&gt;Okay see below that flags any value that is ^ length 20 and ^decimal 5:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input col1;
	col = length(put(col1,best20.));
	decimal = length(scan(strip(put(col1,best20.)),2,"."));

	if col = 20 and decimal = 5 then
		pass = 1;
	else pass=0;
	drop decimal col;
	datalines;
0.01238788
61.15612
123.12
12.1244
12345.125665
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Feb 2021 06:23:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721196#M223486</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-02-23T06:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern checking for decimal numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721258#M223529</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/370640"&gt;@msr1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yes it is format 20.5 with 5 digits after decimal.&lt;BR /&gt;I am not sure about the regex, I took it from the internet.&lt;BR /&gt;My concern is, I need to perform validation on my data, and need to verify it all the values are in format 20.5, anything apart from that will fail.&lt;BR /&gt;Its not on one table, have to do it for multiple table&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are your fields numeric?&amp;nbsp; Is the 20.5 the SAS format or the Teradata field definition.&amp;nbsp; They are different.&amp;nbsp; A DECIMAL(20,5) field in Teradata has space for 20 digits of which 5 are after the decimal place.&amp;nbsp; A SAS format of 20.5 has space for just 19 digits or which 5 are after the decimal place.&amp;nbsp; Also note that SAS stores all numbers as floating point numbers and so it cannot store 30 or even 20 digits precisely.&amp;nbsp; &amp;nbsp;If you actually had a field defined as DECIMAL(30,5) in Teradata you would either need to convert it to FLOAT and lose some of the decimal digit precision or convert it to character and treat it as such in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To test if a number you have it SAS will "fit" into a specific DECIMAL field in Teradata you probably want to use arithmetic and not regular expressions to check.&amp;nbsp; So if the maximum number of decimal places is 5 then round the value to that many decimal places.&amp;nbsp; If the maximum number of decimal places to the left of the decimal place is 15 then make sure the magnitude of the number is smaller than 10**15.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 13:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721258#M223529</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-23T13:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern checking for decimal numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721380#M223582</link>
      <description>No negative numbers? &lt;BR /&gt;</description>
      <pubDate>Tue, 23 Feb 2021 19:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-checking-for-decimal-numbers/m-p/721380#M223582</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-02-23T19:53:47Z</dc:date>
    </item>
  </channel>
</rss>

