<?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: Parse a long text field with varying length results to new variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-long-text-field-with-varying-length-results-to-new/m-p/425008#M104670</link>
    <description>&lt;P&gt;If both first and last name are&amp;nbsp;guaranteed not to have any spaces, you can just use SCAN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you specify 4 spaces because you want to treat single spaces as non-delimiters, then you have a few options.&amp;nbsp; The easiest is to use DLMSTR as '&amp;nbsp; &amp;nbsp; ', I think.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length first last $50;
infile datalines dlmstr='    ';
input
first $ last $;
;;;;
datalines;
JOHN    DOE
MARY ELIZABETH    SMITH
JACKIE    DOE
SOPHIE    DOE
;;;;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you have other fields and want to read them as fixed width, you could read into NAME, then FIND '&amp;nbsp; &amp;nbsp;' and then use SUBSTR to parse it, or a perl regular expression.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jan 2018 17:59:37 GMT</pubDate>
    <dc:creator>snoopy369</dc:creator>
    <dc:date>2018-01-04T17:59:37Z</dc:date>
    <item>
      <title>Parse a long text field with varying length results to new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-long-text-field-with-varying-length-results-to-new/m-p/425005#M104667</link>
      <description>&lt;P&gt;I have a text file that is not delimited and my name field looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;JOHN&amp;nbsp;&amp;nbsp;&amp;nbsp; DOE&lt;/P&gt;
&lt;P&gt;MARYELIZABETH&amp;nbsp;&amp;nbsp;&amp;nbsp; SMITH&lt;/P&gt;
&lt;P&gt;JACKIE&amp;nbsp;&amp;nbsp;&amp;nbsp; DOE&lt;/P&gt;
&lt;P&gt;SOPHIE&amp;nbsp;&amp;nbsp;&amp;nbsp; DOE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The field is $50. as name AND there are four spaces in between the firstname and the lastname&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I parse it to give me FIRST NAME AND LAST NAME&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 17:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-a-long-text-field-with-varying-length-results-to-new/m-p/425005#M104667</guid>
      <dc:creator>myboys2</dc:creator>
      <dc:date>2018-01-04T17:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: Parse a long text field with varying length results to new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-long-text-field-with-varying-length-results-to-new/m-p/425006#M104668</link>
      <description>&lt;P&gt;did you try scan function?&lt;/P&gt;&lt;P&gt;data output;&lt;/P&gt;&lt;P&gt;set input;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;FIRST_NAME=scan(name, 1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;LAST_NAME=scan(name,2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 17:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-a-long-text-field-with-varying-length-results-to-new/m-p/425006#M104668</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-04T17:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Parse a long text field with varying length results to new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-long-text-field-with-varying-length-results-to-new/m-p/425008#M104670</link>
      <description>&lt;P&gt;If both first and last name are&amp;nbsp;guaranteed not to have any spaces, you can just use SCAN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you specify 4 spaces because you want to treat single spaces as non-delimiters, then you have a few options.&amp;nbsp; The easiest is to use DLMSTR as '&amp;nbsp; &amp;nbsp; ', I think.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length first last $50;
infile datalines dlmstr='    ';
input
first $ last $;
;;;;
datalines;
JOHN    DOE
MARY ELIZABETH    SMITH
JACKIE    DOE
SOPHIE    DOE
;;;;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you have other fields and want to read them as fixed width, you could read into NAME, then FIND '&amp;nbsp; &amp;nbsp;' and then use SUBSTR to parse it, or a perl regular expression.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 17:59:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-a-long-text-field-with-varying-length-results-to-new/m-p/425008#M104670</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2018-01-04T17:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Parse a long text field with varying length results to new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-long-text-field-with-varying-length-results-to-new/m-p/425016#M104673</link>
      <description>&lt;P&gt;thanks I did try what you said and also this and both did not work&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;first_nm=scan(r_name,1,' ');&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; last_nm=scan(r_name,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;' '&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 18:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-a-long-text-field-with-varying-length-results-to-new/m-p/425016#M104673</guid>
      <dc:creator>myboys2</dc:creator>
      <dc:date>2018-01-04T18:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Parse a long text field with varying length results to new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-long-text-field-with-varying-length-results-to-new/m-p/425019#M104674</link>
      <description>I ended up doing this - thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;format lname $15.;&lt;BR /&gt;format fname $15.;&lt;BR /&gt;lname=scan(r_name,1,'    ');&lt;BR /&gt;fname=left(scan(r_name,2,'    '))</description>
      <pubDate>Thu, 04 Jan 2018 18:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-a-long-text-field-with-varying-length-results-to-new/m-p/425019#M104674</guid>
      <dc:creator>myboys2</dc:creator>
      <dc:date>2018-01-04T18:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Parse a long text field with varying length results to new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-long-text-field-with-varying-length-results-to-new/m-p/425049#M104686</link>
      <description>&lt;P&gt;Ok Good &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 20:26:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-a-long-text-field-with-varying-length-results-to-new/m-p/425049#M104686</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-04T20:26:56Z</dc:date>
    </item>
  </channel>
</rss>

