<?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 Comma-Embedded Numbers into Numeric Variable? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/74611#M21667</link>
    <description>If I understand your question correct - try&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
  set data;&lt;BR /&gt;
  format var_new 8.;&lt;BR /&gt;
  var_new = input(var_old,best.);&lt;BR /&gt;
run;</description>
    <pubDate>Tue, 06 Oct 2009 21:17:47 GMT</pubDate>
    <dc:creator>GertNissen</dc:creator>
    <dc:date>2009-10-06T21:17:47Z</dc:date>
    <item>
      <title>How to Read Comma-Embedded Numbers into Numeric Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/74610#M21666</link>
      <description>Hi, I just run into another problem about data conversion -&lt;BR /&gt;
&lt;BR /&gt;
I want to create a new numeric variable VAR_NEW to equal an existing SAS variable VAR_OLD. However, the numbers contained in VAR_OLD have embedded commas, such as "1,026", "3,085", which makes it essentially in a string format aligned in the middle of the variable column.&lt;BR /&gt;
&lt;BR /&gt;
As a result, the value of VAR_NEW becomes missing whenever a VAR_OLD value is greater than 999. So, what is the easy way to generate VAR_NEW without the missing value issue?&lt;BR /&gt;
&lt;BR /&gt;
Thanks a lot!&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: SASLooker

Message was edited by: SASLooker</description>
      <pubDate>Tue, 06 Oct 2009 20:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/74610#M21666</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-06T20:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read Comma-Embedded Numbers into Numeric Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/74611#M21667</link>
      <description>If I understand your question correct - try&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
  set data;&lt;BR /&gt;
  format var_new 8.;&lt;BR /&gt;
  var_new = input(var_old,best.);&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 06 Oct 2009 21:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/74611#M21667</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2009-10-06T21:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read Comma-Embedded Numbers into Numeric Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/74612#M21668</link>
      <description>Hi Geniz,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the suggestion. I tried that, but that makes var_new entirely into missing values.&lt;BR /&gt;
&lt;BR /&gt;
But following your direction, I came across this, and it worked perfectly -&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
set data;&lt;BR /&gt;
var_new = input(var_old, comma8.);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Although the result is satisfactory, I am not so sure if using COMMAw.d this way is technically correct, or I just got lucky. Because the doumentation I found about COMMAw.d typically refers to reading external file rather than to converting a SAS internal data file. So, I'd like to hear the others' confirmation or verification.</description>
      <pubDate>Tue, 06 Oct 2009 21:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/74612#M21668</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-06T21:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read Comma-Embedded Numbers into Numeric Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/74613#M21669</link>
      <description>The COMMAw.d and other informats tell SAS how to interprete a string for converting it into a SAS number. This string can of course be stored in a SAS character variable.</description>
      <pubDate>Tue, 06 Oct 2009 22:11:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/74613#M21669</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-10-06T22:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read Comma-Embedded Numbers into Numeric Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/74614#M21670</link>
      <description>SASLooker,&lt;BR /&gt;
&lt;BR /&gt;
It's not clear from your message where VAR_OLD comes from. Are you reading it in as a character variable? If so, then read it as a numeric variable using the COMMAw.d informat, as Patrick suggested.&lt;BR /&gt;
&lt;BR /&gt;
In your INPUT statement, the code &lt;BR /&gt;
&lt;BR /&gt;
VAR_OLD :COMMA5. &lt;BR /&gt;
&lt;BR /&gt;
will read anything up to four digits, with or without a comma, as a numeric variable. The colon modifier tells SAS to ignore the width (5) and lets you read anything from one- to four-digit numbers. If you don't include the colon modifier and there are numbers less than 1,000, you won't get the expected results for those numbers.&lt;BR /&gt;
&lt;BR /&gt;
If it's in a permanent SAS data set rather than one you are creating when you run your program, never mind!&lt;BR /&gt;
&lt;BR /&gt;
liz</description>
      <pubDate>Thu, 08 Oct 2009 20:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/74614#M21670</guid>
      <dc:creator>Liz_LSU</dc:creator>
      <dc:date>2009-10-08T20:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read Comma-Embedded Numbers into Numeric Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/74615#M21671</link>
      <description>thanks for the tip, liz! I am dealing with a permanent SAS data, and for now, everything seems to work out. But I'll bear your suggestion in mind if I deal with other situations.</description>
      <pubDate>Fri, 09 Oct 2009 14:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/74615#M21671</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-09T14:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read Comma-Embedded Numbers into Numeric Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/884839#M82839</link>
      <description>&lt;P&gt;If you have a comma in a text field using the comma8. input statement works; the best will not format it correctly and continue with the same problem.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 17:31:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/884839#M82839</guid>
      <dc:creator>SuperSas1</dc:creator>
      <dc:date>2023-07-14T17:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to Read Comma-Embedded Numbers into Numeric Variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/884850#M82840</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/445898"&gt;@SuperSas1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;If you have a comma in a text field using the comma8. input statement works; the best will not format it correctly and continue with the same problem.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not sure why you are responding to an ancient thread....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The INPUT() function does not mind if the width used on the informat is larger than the length of the string being read, so in general you should just use the maximum width that the informat supports.&amp;nbsp; For COMMA that is 32.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;number = input(string,comma32.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also notice that do not want to include a decimal width on an informat except for the rare occasion when you know the strings being read were created explicitly without the decimal point and want SAS to divide by that power of 10 to insert one.&amp;nbsp; This is normally not done for strings that include commas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note also the BEST is the name of a FORMAT.&amp;nbsp; Its name comes from its attempt to find the "best" way to display a number in a limited number of characters.&amp;nbsp; There is no corresponding concept of the "best" way to store a string as a number.&amp;nbsp; Numbers in SAS can only be stored one way, as 64 bit binary floating point values.&amp;nbsp; If you use BEST as an informat then SAS just assumes you meant to use the normal numeric informat, which does not work with strings that contain commas.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 18:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Read-Comma-Embedded-Numbers-into-Numeric-Variable/m-p/884850#M82840</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-14T18:13:08Z</dc:date>
    </item>
  </channel>
</rss>

