<?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: ANSI encoded text fix line breaks in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595581#M15826</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294547"&gt;@Emma8&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've only realized that I've missed what you're dealing with when I read&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s answer. The resolution I've provided in your other post is therefore not correct (and I've removed it from there).&lt;/P&gt;
&lt;P&gt;Here the code again with an amendment that will read such date strings broken over two lines. It will only work for the exact pattern of a broken up date string as provided in your sample data. I've also introduced an additional variable&amp;nbsp;&lt;EM&gt;Date_String&lt;/EM&gt; which contains the source string before we try to convert it into a SAS date.&amp;nbsp; This to keep invalid date strings in your target data - like&amp;nbsp;09/00/1990 from your sample - so you can later on add some additional logic as you need it to eventually fix such dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*filename src &amp;lt;path/filename.txt&amp;gt; lrecl=256;*/

data want(drop=_:);
  length
    Source $11
    Id $8
    Name $80
    Visit $15
    ;
  format Birthday date9. Date date9.;
  infile src scanover truncover col=_col;
  input @;

  if find(_infile_,'Master File:')&amp;gt;0 then
    do;
      source='Master File';
      input @1 @'Master File:' +1 ID $8. @;
    end;
  else 
  if find(_infile_,'DDDI File:')&amp;gt;0 then
    do;
      source='DDDI File';
      input @1 @'DDDI File:' +1 ID $8. @;
    end;
  else delete;

  /* name */
  input @_col @'Name:' +(-1) _dummy $1.@;
  _start=_col;
  input @_col @'VIS:' +(-5) _dummy $1. @;
  _stop=_col;
  _fwidth=_stop - _start;
  input @_start Name $varying80. _fwidth @;
  name=compbl(name);

  /* visit */
  _start=_col+5;
  input @_col @'Birthdate:' +(-11) _dummy $1. @;
  _stop=_col;
  _fwidth=_stop - _start;
  input @_start visit $varying15. _fwidth @;

  /* Birthdate*/
  input @'Birthdate:' Birthday :mmddyy10. @;

  /* Date - also addresses case of date string broken over two source lines */
  length Date_String $10;
  input @':' Date_String:$10.;
  if lengthn(Date_String)=10 then Date=input(Date_String,?? mmddyy10.);
  else
    do;
      input @@;
      if lengthn(_infile_)=2 then
        do;
          Date_String=cats(Date_String,_infile_);
          Date=input(Date_String,?? mmddyy10.);
          input;
        end;
    end;

run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33057i7623B0C3188D3C60/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Oct 2019 22:35:32 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-10-10T22:35:32Z</dc:date>
    <item>
      <title>ANSI encoded text fix line breaks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595460#M15804</link>
      <description>&lt;P&gt;Hello, I have a text file that some observations have line breaks (Date of last seen, attached).&lt;/P&gt;&lt;P&gt;When I read into SAS how can I fix this line breaks? Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 15:46:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595460#M15804</guid>
      <dc:creator>Emma8</dc:creator>
      <dc:date>2019-10-10T15:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: ANSI encoded text fix line breaks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595463#M15806</link>
      <description>&lt;P&gt;Is this the data you dumped from WORD?&amp;nbsp; Can you just change the margins/font on the word file to prevent line wrapping before converting it to text?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could probably fix this by reading in the file and writing it back out without the extra line breaks.&amp;nbsp; You could even make so each record is all on one line.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 infile original;
 file fix;
 input;
 if _n_&amp;gt;1 and left(_infile_)=:'Master File:' then put;
 len=lengthn(_infile_);
 put _infile_ $varying200. len @;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then reading the fixed file will be easier since all of the values for one line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 16:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595463#M15806</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-10T16:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: ANSI encoded text fix line breaks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595466#M15807</link>
      <description>&lt;P&gt;Have you done anything at all to that file since receipt? Or possibly someone else editing it in some fashion such as replacing tab characters?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Typically I would expect the line lengths where the values are cutoff to be at the same position but that is not the case here.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 16:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595466#M15807</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-10T16:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: ANSI encoded text fix line breaks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595506#M15819</link>
      <description>&lt;P&gt;Great! Thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 17:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595506#M15819</guid>
      <dc:creator>Emma8</dc:creator>
      <dc:date>2019-10-10T17:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: ANSI encoded text fix line breaks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595581#M15826</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294547"&gt;@Emma8&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've only realized that I've missed what you're dealing with when I read&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s answer. The resolution I've provided in your other post is therefore not correct (and I've removed it from there).&lt;/P&gt;
&lt;P&gt;Here the code again with an amendment that will read such date strings broken over two lines. It will only work for the exact pattern of a broken up date string as provided in your sample data. I've also introduced an additional variable&amp;nbsp;&lt;EM&gt;Date_String&lt;/EM&gt; which contains the source string before we try to convert it into a SAS date.&amp;nbsp; This to keep invalid date strings in your target data - like&amp;nbsp;09/00/1990 from your sample - so you can later on add some additional logic as you need it to eventually fix such dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*filename src &amp;lt;path/filename.txt&amp;gt; lrecl=256;*/

data want(drop=_:);
  length
    Source $11
    Id $8
    Name $80
    Visit $15
    ;
  format Birthday date9. Date date9.;
  infile src scanover truncover col=_col;
  input @;

  if find(_infile_,'Master File:')&amp;gt;0 then
    do;
      source='Master File';
      input @1 @'Master File:' +1 ID $8. @;
    end;
  else 
  if find(_infile_,'DDDI File:')&amp;gt;0 then
    do;
      source='DDDI File';
      input @1 @'DDDI File:' +1 ID $8. @;
    end;
  else delete;

  /* name */
  input @_col @'Name:' +(-1) _dummy $1.@;
  _start=_col;
  input @_col @'VIS:' +(-5) _dummy $1. @;
  _stop=_col;
  _fwidth=_stop - _start;
  input @_start Name $varying80. _fwidth @;
  name=compbl(name);

  /* visit */
  _start=_col+5;
  input @_col @'Birthdate:' +(-11) _dummy $1. @;
  _stop=_col;
  _fwidth=_stop - _start;
  input @_start visit $varying15. _fwidth @;

  /* Birthdate*/
  input @'Birthdate:' Birthday :mmddyy10. @;

  /* Date - also addresses case of date string broken over two source lines */
  length Date_String $10;
  input @':' Date_String:$10.;
  if lengthn(Date_String)=10 then Date=input(Date_String,?? mmddyy10.);
  else
    do;
      input @@;
      if lengthn(_infile_)=2 then
        do;
          Date_String=cats(Date_String,_infile_);
          Date=input(Date_String,?? mmddyy10.);
          input;
        end;
    end;

run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33057i7623B0C3188D3C60/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 22:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595581#M15826</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-10-10T22:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: ANSI encoded text fix line breaks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595679#M15842</link>
      <description>Thank you so much</description>
      <pubDate>Fri, 11 Oct 2019 11:17:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595679#M15842</guid>
      <dc:creator>Emma8</dc:creator>
      <dc:date>2019-10-11T11:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: ANSI encoded text fix line breaks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595682#M15843</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294547"&gt;@Emma8&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To check if there are any date strings either not in the right format or the date string doesn't represent a valid date, code as below should do.&lt;/P&gt;
&lt;P&gt;Date strings not in the right format could be caused by your source data also being broken up onto more than one line in a different way than what you've shown us so far. You need to investigate if there are such cases and eventually provide sample data which reflect all cases you have in your real data (if there is more).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value $case
    '01'='date string missing or incomplete'
    '02'='date string in the correct pattern but date invalid'
  ;
run;
data dq;
  format case $case.;
  set want;
  if not prxmatch('/\d\d\/\d\d\/\d{4}/oi',date_string) then 
    do;
      case='01';
      output;
    end;
  else
  if missing(date) then
    do;
      case='02';
      output;
    end;
run;
proc print;
run;&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 11:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595682#M15843</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-10-11T11:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: ANSI encoded text fix line breaks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595687#M15844</link>
      <description>Very helpful. Thank you so much!&lt;BR /&gt;Have a pleasant weekend and holiday</description>
      <pubDate>Fri, 11 Oct 2019 12:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/ANSI-encoded-text-fix-line-breaks/m-p/595687#M15844</guid>
      <dc:creator>Emma8</dc:creator>
      <dc:date>2019-10-11T12:00:13Z</dc:date>
    </item>
  </channel>
</rss>

