<?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 character text with hyphen to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/771832#M244986</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
LENGTH ID $ 10;
input ID $ ;
cards;
840-02-001
840-02-002
840-02-003
;
run;

data want;
 set have;
 IDnum=input(compress(ID,'-'),10.);
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 03 Oct 2021 21:34:51 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2021-10-03T21:34:51Z</dc:date>
    <item>
      <title>Converting character text with hyphen to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/771830#M244985</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have data where the ID of the people are in character format and the data looks like this&lt;/P&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;840-02-001&lt;/P&gt;&lt;P&gt;840-02-002&lt;/P&gt;&lt;P&gt;840-02-003&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please suggest how to convert this text to numeric so that i can sort and also convert back to same character text. Since i cant sort the data with this id variable because it is character.&lt;/P&gt;&lt;P&gt;data id;&lt;/P&gt;&lt;P&gt;set name;&lt;/P&gt;&lt;P&gt;ptid =input(id,10.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Help to correct the code for reading character with Hyphen and converting to numeric for sorting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;</description>
      <pubDate>Sun, 03 Oct 2021 21:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/771830#M244985</guid>
      <dc:creator>venkatagopinath</dc:creator>
      <dc:date>2021-10-03T21:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character text with hyphen to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/771832#M244986</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
LENGTH ID $ 10;
input ID $ ;
cards;
840-02-001
840-02-002
840-02-003
;
run;

data want;
 set have;
 IDnum=input(compress(ID,'-'),10.);
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Oct 2021 21:34:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/771832#M244986</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-10-03T21:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character text with hyphen to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/771837#M244989</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;Since i cant sort the data with this id variable because it is character.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's an odd comment. Why can't you?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Oct 2021 22:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/771837#M244989</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-10-03T22:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character text with hyphen to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/771840#M244991</link>
      <description>Thank you&lt;BR /&gt;</description>
      <pubDate>Sun, 03 Oct 2021 23:03:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/771840#M244991</guid>
      <dc:creator>venkatagopinath</dc:creator>
      <dc:date>2021-10-03T23:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character text with hyphen to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/771844#M244994</link>
      <description>&lt;P&gt;Based on the data you have supplied the sort order will be the same if you compare a character sort with a numeric sort. Why bother converting?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 00:12:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/771844#M244994</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-10-04T00:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character text with hyphen to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/771848#M244997</link>
      <description>&lt;P&gt;Why? Where are you going to perform arithmetic with ID values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your example doesn't show any likely problem with sorting, so provide a more complex example that did not sort the way you expect it to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc sort has options like Sortseq with LInguistic and Numeric_Collation that allows you to override or specify some additional behaviors such as the numeric value instead of the default character order sort, ie "8 Main St" can come before "45 Main St".&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 04:10:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/771848#M244997</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-04T04:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character text with hyphen to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/772086#M245116</link>
      <description>&lt;P&gt;There's no problem sorting character values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length ID $ 10;
input ID;
cards;
840-02-001
840-02-002
840-02-003
;

proc sort data=have;
by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt; 69         data have;
 70         length ID $ 10;
 71         input ID;
 72         cards;
 
 NOTE: The data set WORK.HAVE has 3 observations and 1 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       user cpu time       0.01 seconds
 
 76         ;
 77         
 78         proc sort data=have;
 79         by id;
 80         run;
 
 NOTE: There were 3 observations read from the data set WORK.HAVE.
 NOTE: The data set WORK.HAVE has 3 observations and 1 variables.
 NOTE:  Verwendet wurde: PROZEDUR SORT - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       user cpu time       0.00 seconds
&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Oct 2021 08:22:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-character-text-with-hyphen-to-numeric/m-p/772086#M245116</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-05T08:22:29Z</dc:date>
    </item>
  </channel>
</rss>

