<?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: text to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915109#M360601</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks Tom!! &lt;BR /&gt;Another qu is: lets say apple was decimal(17,2) in db2. Now i read as 19., how would it display in sas dataset?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you don't attach any format to the variable then it will normally print like BEST12. format.&amp;nbsp; (If you, for some strange reason, ask PROC SQL to print output I think it will use BEST8. instead.)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So values that are small will look like 1234.56.&amp;nbsp; But large values will have to resort to use scientific notation to be able to indicate the magnitude of the value in only 12 characters.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can just try it yourself.&amp;nbsp; &amp;nbsp;Just run a data step and a PROC PRINT step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input x 19.;
cards;
1
1234.56
1234567890123456789
;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs            x

 1          1.00
 2       1234.56
 3     1.2346E18
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Feb 2024 16:08:42 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-02-08T16:08:42Z</dc:date>
    <item>
      <title>text to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915003#M360572</link>
      <description>&lt;P&gt;hi I have a file with columns and I know that they are string and the length&lt;/P&gt;
&lt;P&gt;so I read them in and for those columns that is decimal&lt;/P&gt;
&lt;P&gt;I will have to format it to say 4., 10.2 etc&lt;/P&gt;
&lt;P&gt;my questions is I know the schema from db2 where the text file is converted from&lt;/P&gt;
&lt;P&gt;so suppose I will use db2 schema for decimal(17,2)&lt;/P&gt;
&lt;P&gt;to format these numeric column&lt;/P&gt;
&lt;P&gt;so if in db2 these schema is decimal(17,2)&lt;/P&gt;
&lt;P&gt;I will format this column like this:&lt;/P&gt;
&lt;P&gt;format col 17.2&lt;/P&gt;
&lt;P&gt;??&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 05:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915003#M360572</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2024-02-08T05:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: text to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915004#M360573</link>
      <description>&lt;P&gt;And what does DB2 mean by the data TYPE of DECIMAL(17,2)?&lt;/P&gt;
&lt;P&gt;Does that mean 17 decimal digits two of which are after the decimal point?&lt;BR /&gt;Or 19 decimal digits, two of which are after the decimal point?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the fields in your DB2 file actually had numbers larger than 90,071,992,547,409.92&amp;nbsp;(which is not quite a full 16 decimal places) then you cannot store such a number exactly in ONE numeric variable in SAS.&amp;nbsp; That is because SAS uses floating point binary numbers.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;354  data _null_;
355   max = constant('exactint');
356   put max= 32. max= comma32. ;
357  run;

max=9007199254740992 max=9,007,199,254,740,992
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What type of numbers are stored in that field?&amp;nbsp; Is it using two decimal places because it is supposed to represent dollars?&amp;nbsp; If so then to store the values exactly you will want to multiply by 100 so you do not have decimal fractions.&amp;nbsp; A fraction like one tenth (0.10) cannot be stored exactly using base 2 floating point numbers.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS you use a FORMAT to tell it how to PRINT the values.&amp;nbsp; For numbers the format width counts all of the characters, not just the digits, including any decimal point or negative sign.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming the you don't mind some small lose of precision (because of values that are too large or values like one tenth that cannot be stored precisely) to print a number with 19 digits you would need to use a format with a width of 20 when you want to include a decimal point.&amp;nbsp; &amp;nbsp;&lt;STRONG&gt;So use format of 20.2.&amp;nbsp;&lt;/STRONG&gt; &amp;nbsp;&amp;nbsp;And you might need a width of 21 if you could have really large negative values since the - used to indicate a negative value will take up one character position also.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 05:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915004#M360573</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-08T05:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: text to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915017#M360580</link>
      <description>&lt;P&gt;You say "file", but you also say "DB2". So do you read a file that was extracted from the database, or do you use a direct connection to the database via SAS/ACCESS?&lt;/P&gt;
&lt;P&gt;If you read from a text file, open it with an editor and copy/paste a few lines into a window opened with the &amp;lt;/&amp;gt; button.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 09:23:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915017#M360580</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-08T09:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: text to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915024#M360585</link>
      <description>If db2 output as string say 10.5, can I input as say 19. , i testes it is reading fine but i worry it is still character in sas dataset and cannit be used for calculation&lt;BR /&gt;If it read fine without error does it mean it is already recognise as numeric value?</description>
      <pubDate>Thu, 08 Feb 2024 12:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915024#M360585</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2024-02-08T12:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: text to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915028#M360586</link>
      <description>&lt;P&gt;For those situations where you really need 17 or 18 or 19 or more digits to do arithmetic, you probably need to use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n0ujllmd28quj5n17r2ibrdya9ld.htm" target="_self"&gt;PROC DS2&lt;/A&gt;. But do you really need to do arithmetic on these long numbers?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 12:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915028#M360586</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-08T12:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: text to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915050#M360590</link>
      <description>I am not clear let me explain again. Say We have a table from db2. In fb2 some columns are character some are numeric value. But the table was output into a file. And colleague saud in the output file all columns are string. Since i know some are actually numeric value in db2 before output as a file. So when in sas, i read the file like below:&lt;BR /&gt;Input &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/308480"&gt;@002&lt;/a&gt; apple 19. When i know apple was decimal and length is 19. And i didnt format the column as numeric again after read from infile. Now my question is, &lt;BR /&gt;1. would my sas program run fine? That is reading apple as numbers? &lt;BR /&gt;2. If it does run without error, does it mean now in column apple it is number and can be used as numbers eg for calculation ?&lt;BR /&gt;3. What i dont understand is my colleague say col apple is string, how does sas know if string or number as it is a text file, it does look like number.</description>
      <pubDate>Thu, 08 Feb 2024 14:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915050#M360590</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2024-02-08T14:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: text to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915058#M360591</link>
      <description>&lt;P&gt;1)&amp;nbsp; The program will run fine as long as the value for apple, and only for apple, is in the 2nd through 20th column of each line of the text file you are reading.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Yes. It you read using a NUMERIC informat then you have created a numeric variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) Everything in a text file is a string.&amp;nbsp; SAS does not know (no computer program could know) whether the text in your file is supposed to represent numbers or character strings.&amp;nbsp; That is something you need to know before writing the program to read it.&amp;nbsp; You should have received a description of the file that you could use to make your decision of how to read it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And this statement you made is confused:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;And i didnt format the column as numeric again after read from infile.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You do not "format the column as numeric".&amp;nbsp; You can MAKE or DEFINE the column as numeric.&amp;nbsp; If you defined the variable as numeric in a LENGTH statement.&amp;nbsp; Or if SAS made it numeric because the first place you used it your code treated it as numeric.&amp;nbsp; Then it is numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A FORMAT is just instructions you can OPTIONALLY attach to a variable that describe how you want the value to PRINT.&amp;nbsp; It is what determines how the values will appear when you make a new text file from your data.&amp;nbsp; You cannot use a FORMAT to change the TYPE of the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 14:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915058#M360591</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-08T14:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: text to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915090#M360597</link>
      <description>Thanks Tom!! &lt;BR /&gt;Another qu is: lets say apple was decimal(17,2) in db2. Now i read as 19., how would it display in sas dataset?</description>
      <pubDate>Thu, 08 Feb 2024 15:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915090#M360597</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2024-02-08T15:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: text to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915091#M360598</link>
      <description>&lt;P&gt;1) Maxim 4: Try It.&lt;/P&gt;
&lt;P&gt;2) Visually compare the text file with what you get in SAS.&lt;/P&gt;
&lt;P&gt;3) SAS doesn't know anything.&amp;nbsp;&lt;STRONG&gt;YOU&lt;/STRONG&gt; tell it through your code what to do.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 15:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915091#M360598</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-08T15:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: text to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915109#M360601</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks Tom!! &lt;BR /&gt;Another qu is: lets say apple was decimal(17,2) in db2. Now i read as 19., how would it display in sas dataset?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you don't attach any format to the variable then it will normally print like BEST12. format.&amp;nbsp; (If you, for some strange reason, ask PROC SQL to print output I think it will use BEST8. instead.)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So values that are small will look like 1234.56.&amp;nbsp; But large values will have to resort to use scientific notation to be able to indicate the magnitude of the value in only 12 characters.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can just try it yourself.&amp;nbsp; &amp;nbsp;Just run a data step and a PROC PRINT step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input x 19.;
cards;
1
1234.56
1234567890123456789
;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs            x

 1          1.00
 2       1234.56
 3     1.2346E18
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 16:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915109#M360601</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-08T16:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: text to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915153#M360612</link>
      <description>If apple is actually date in format 2022-11-30, can i input straight away using date informat? &lt;BR /&gt;&lt;BR /&gt;Eg from infile&lt;BR /&gt;Input &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/308480"&gt;@002&lt;/a&gt; apple yymmdd10.;&lt;BR /&gt;&lt;BR /&gt;Or i really have read with infirmat $10.&lt;BR /&gt;Then do input(apple,yymmdd10.) then format apple date9.?</description>
      <pubDate>Thu, 08 Feb 2024 21:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915153#M360612</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2024-02-08T21:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: text to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915155#M360613</link>
      <description>&lt;P&gt;Why not just try it for yourself? ALL date strings can typically be read directly into SAS dates as long as there is an INFORMAT to handle it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want;
  input @1 apple yymmdd10.;
  format apple date9.;
  put apple=;
cards;
2022-11-30
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASKiwi_0-1707428884066.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93434i2C8C43A7AB3F6BD5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASKiwi_0-1707428884066.png" alt="SASKiwi_0-1707428884066.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 21:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/text-to-numeric/m-p/915155#M360613</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2024-02-08T21:50:54Z</dc:date>
    </item>
  </channel>
</rss>

