<?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: Reading standard delimited lines, with a twist in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-standard-delimited-lines-with-a-twist/m-p/502235#M134043</link>
    <description>&lt;P&gt;So you know&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the first and last items do not have a delimiter in it&lt;/LI&gt;
&lt;LI&gt;you have three items overall&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;First, get a count of "words" with countw(_infile_)&lt;/P&gt;
&lt;P&gt;scan(_infile_,1) is your first item&lt;/P&gt;
&lt;P&gt;scan(_infile_,countw(_infile_)) is your last item&lt;/P&gt;
&lt;P&gt;loop from 2 to countw() - 1 to get all the "middle words" and concatenate them with catx.&lt;/P&gt;</description>
    <pubDate>Sun, 07 Oct 2018 10:17:06 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-10-07T10:17:06Z</dc:date>
    <item>
      <title>Reading standard delimited lines, with a twist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-standard-delimited-lines-with-a-twist/m-p/502226#M134040</link>
      <description>&lt;P&gt;I'm struggling to figure out how to put these datelines in a data step.&lt;/P&gt;&lt;P&gt;The first variable is the first set of numbers, which is the ID, they can be variable.&lt;/P&gt;&lt;P&gt;The last variable is the last two letters, representing country.&lt;/P&gt;&lt;P&gt;The middle variable is all of the stuff between the ID and Country Code, namely the Business Name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;47185 KN Outdoor Trading Inc US&lt;BR /&gt;4742 Luna sastreria S.A. ES&lt;BR /&gt;479 Norsok A/S DK&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would normally try to manually align the code to fix problem, however, my data is quite large.&lt;/P&gt;&lt;P&gt;Is there a way to make the last 2 letters of the string in the datalines align to the right to make it easier?&lt;/P&gt;&lt;P&gt;Or is there a better solution to this problem?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Oct 2018 08:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-standard-delimited-lines-with-a-twist/m-p/502226#M134040</guid>
      <dc:creator>MikeYick</dc:creator>
      <dc:date>2018-10-07T08:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: Reading standard delimited lines, with a twist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-standard-delimited-lines-with-a-twist/m-p/502232#M134041</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/238776"&gt;@MikeYick&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Actually, it's only the the missing double blank between business name (containing blanks) and country that lets modified list input fail. So, one way to read the data is&amp;nbsp;to let SAS insert the missing blank:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input @;
_infile_=prxchange('s/(.+) (\w+)/$1  $2/',1,_infile_);
input ID :$12. business &amp;amp;$40. country :$2.;
cards;
47185 KN Outdoor Trading Inc US
4742 Luna sastreria S.A. ES
479 Norsok A/S DK
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;You may want to modify the suggested lengths (12, 40, 2) as needed (e.g. start with generous lengths and then determine the maximum actual length of the values of each variable).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Oct 2018 10:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-standard-delimited-lines-with-a-twist/m-p/502232#M134041</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-10-07T10:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Reading standard delimited lines, with a twist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-standard-delimited-lines-with-a-twist/m-p/502235#M134043</link>
      <description>&lt;P&gt;So you know&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the first and last items do not have a delimiter in it&lt;/LI&gt;
&lt;LI&gt;you have three items overall&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;First, get a count of "words" with countw(_infile_)&lt;/P&gt;
&lt;P&gt;scan(_infile_,1) is your first item&lt;/P&gt;
&lt;P&gt;scan(_infile_,countw(_infile_)) is your last item&lt;/P&gt;
&lt;P&gt;loop from 2 to countw() - 1 to get all the "middle words" and concatenate them with catx.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Oct 2018 10:17:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-standard-delimited-lines-with-a-twist/m-p/502235#M134043</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-07T10:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Reading standard delimited lines, with a twist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-standard-delimited-lines-with-a-twist/m-p/502236#M134044</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
input;
call scan(_infile_,1,p1,l1,' ');
call scan(_infile_,-1,p2,l2,' ');
id=scan(_infile_,1,' ');
business=substr(_infile_,p1+l1,p2-p1-l1);
country=scan(_infile_,-1,' ');
drop p1 l1 p2 l2;
cards;
47185 KN Outdoor Trading Inc US
4742 Luna sastreria S.A. ES
479 Norsok A/S DK
;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Oct 2018 10:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-standard-delimited-lines-with-a-twist/m-p/502236#M134044</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-07T10:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Reading standard delimited lines, with a twist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-standard-delimited-lines-with-a-twist/m-p/502248#M134048</link>
      <description>&lt;P&gt;This is where the use of a negative word position (the -1 in the scan function below) is helpful, because the -1 means the last word in a string of words:&lt;/P&gt;
&lt;P&gt;&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;
  input id  business $60.;
  length country $2.;
  country=scan(business,-1);
  business=substr(business,1,length(business)-length(country));
  put business=;
cards;
47185 KN Outdoor Trading Inc US
4742 Luna sastreria S.A. ES
479 Norsok A/S DK
;&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code initially reads both business and country into the business variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then it gets the last word of business for the country variable&amp;nbsp; (scan with -1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After that just take a substring of business minus the last X characters (where X is length(country)).&lt;/P&gt;</description>
      <pubDate>Sun, 07 Oct 2018 12:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-standard-delimited-lines-with-a-twist/m-p/502248#M134048</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-10-07T12:04:02Z</dc:date>
    </item>
  </channel>
</rss>

