<?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: extract numbers in a text field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431565#M106772</link>
    <description>&lt;P&gt;thanks so much!!&lt;/P&gt;</description>
    <pubDate>Sat, 27 Jan 2018 21:11:55 GMT</pubDate>
    <dc:creator>rykwong</dc:creator>
    <dc:date>2018-01-27T21:11:55Z</dc:date>
    <item>
      <title>extract numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431563#M106770</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a variable "datetext" that contains a set of numbers separated by "/". &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example patient A has datetext="2130/3457/4732"&lt;/P&gt;
&lt;P&gt;each of the 3 numbers is the number of days of patient A to an event, so&amp;nbsp;patient A has this event 3 times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to extract each of the 3 numbers as a number variable so that for patient A:&lt;/P&gt;
&lt;P&gt;date1=2130, date2=3457 and date3=4732&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;many thanks for your help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Raymond&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>Sat, 27 Jan 2018 21:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431563#M106770</guid>
      <dc:creator>rykwong</dc:creator>
      <dc:date>2018-01-27T21:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: extract numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431564#M106771</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datetext="2130/3457/4732";
date1=input(scan(datetext,1,'/'),5.);
date2=input(scan(datetext,2,'/'),5.);
date3=input(scan(datetext,3,'/'),5.);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Jan 2018 21:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431564#M106771</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-27T21:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: extract numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431565#M106772</link>
      <description>&lt;P&gt;thanks so much!!&lt;/P&gt;</description>
      <pubDate>Sat, 27 Jan 2018 21:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431565#M106772</guid>
      <dc:creator>rykwong</dc:creator>
      <dc:date>2018-01-27T21:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: extract numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431573#M106774</link>
      <description>&lt;P&gt;Note that for most analysis scenarios, you will do better in SAS with a &lt;EM&gt;long&lt;/EM&gt; data structure generated by&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datetext="2130/3457/4732";

do event = 1 to countw(datetext);
    daysToEvent = input(scan(datetext), event, "/"), best.);
    output;
    end;
drop datetext;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 Jan 2018 03:06:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431573#M106774</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-01-28T03:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: extract numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431582#M106778</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data q1;
infile datalines dlm="/";
input date1 date2 date3;
datalines;
2130/3457/4732
run;
proc print data=q1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 Jan 2018 08:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431582#M106778</guid>
      <dc:creator>Vipul_Sawlani</dc:creator>
      <dc:date>2018-01-28T08:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: extract numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431613#M106792</link>
      <description>many thanks!</description>
      <pubDate>Sun, 28 Jan 2018 15:42:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431613#M106792</guid>
      <dc:creator>rykwong</dc:creator>
      <dc:date>2018-01-28T15:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: extract numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431897#M106882</link>
      <description>&lt;P&gt;if I may ask one more similar question&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a variable "newtext" that contains a set of numbers numbers (e.g. 2,4,6,7). &amp;nbsp;For example for patient A it is stored in newtext like this "[2/4/6/7]. &amp;nbsp;For a separate patient, it may contain only 2 numbers such as "[4509/21]"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to extract each of these numbers as a number variable so that for patient A:&lt;/P&gt;
&lt;P&gt;date1=2, date2=4&amp;nbsp;date3=6 and date4=7&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;many thanks for your help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 18:41:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431897#M106882</guid>
      <dc:creator>rykwong</dc:creator>
      <dc:date>2018-01-29T18:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: extract numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431905#M106883</link>
      <description>So for the second patient, the values would be: date1=4509 and date2=21? Are those really dates? I have a hard time understanding how 4509 can be a date.&lt;BR /&gt;&lt;BR /&gt;cynthia</description>
      <pubDate>Mon, 29 Jan 2018 18:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431905#M106883</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-01-29T18:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: extract numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431908#M106884</link>
      <description>these are number of days from a reference date (which was determined and set by the system).   So for 4509 it is an interval of 12 years. The purpose of these is to encrypt the date.  So I just need to extract these numbers into separate numeric fields.  A given pt may have none of these numbers or 10 or 15 of these numbers so I am trying to figure out a code to extract accurately.  many thanks &lt;BR /&gt;</description>
      <pubDate>Mon, 29 Jan 2018 19:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/431908#M106884</guid>
      <dc:creator>rykwong</dc:creator>
      <dc:date>2018-01-29T19:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: extract numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/432041#M106933</link>
      <description>HI:&lt;BR /&gt;  I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt; -- the SCAN function will do what you want.&lt;BR /&gt;cynthia</description>
      <pubDate>Tue, 30 Jan 2018 02:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/432041#M106933</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-01-30T02:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: extract numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/432130#M106978</link>
      <description>&lt;P&gt;sorry, but how do I extract the numbers out of the brackets? i.e. want to get 1, 2, 3, and 4 out of "[1/2/3/4]"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 10:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/432130#M106978</guid>
      <dc:creator>rykwong</dc:creator>
      <dc:date>2018-01-30T10:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: extract numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/432194#M107005</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Of course, you could use TRANSLATE, TRANWRD, or COMPRESS functions to disappear away the [ ] before you start, but you can do it all with the SCAN function too. Here's an example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data showit;
  text='[1/2/3/4]';
  x1 = scan(text,1,'[/');
  x2 = scan(text,2,'/');
  x3 = scan(text,3,'/');
  x4 = scan(text,4,'/]');
  putlog _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; Using an ARRAY and a DO loop just makes the program more elegant, however, I wanted to provide proof of concept here, not elegance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Hope this helps,&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 14:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-numbers-in-a-text-field/m-p/432194#M107005</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-01-30T14:14:25Z</dc:date>
    </item>
  </channel>
</rss>

