<?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 data from a unfriendly text file in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399531#M66645</link>
    <description>&lt;P&gt;Define your variables. Don't force SAS to guess what you meant them to be by how they first appear in the code.&lt;/P&gt;
&lt;P&gt;Don't bother with all of those nested IF/THEN statements. Let the natural SAS processing do that work for you. Take advantage of the power of the INPUT statement.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
  infile 'exam.txt' truncover dsd dlm=':';
  length Course $30 StudentName $30 Grade Reportdate 8 ID $10 SchoolCode $8 School $30 DoB 8 District $30 ;
  format ReportDate DoB mmddyy10. ;
  retain Course -- District; 
  length chk $100 ;
  input chk @; 
  if chk = 'Calculus' then input Course ;
  if chk = 'Student' then input StudentName ;
  if chk = 'ID' then input ID ;
  if chk = 'Grade' then input Grade ;
  if chk = 'Date of Birth' then input Dob mmddyy12. ;
  if chk = 'School' then input School ;
  if chk = 'District' then input District ;
  if chk ='Report Date' then do; 
    input Reportdate mmddyy12. ;
    schoolcode =scan(school,1,' ');
    school = substr(school,length(schoolcode)+2);
    output;
    call missing(of _all_);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that SAS can normally read date values with 2 digit years and make the right choice is to what century is meant, but why would want to print your dates without the century?&amp;nbsp; You are just inviting trouble later.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Sep 2017 15:50:41 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-09-28T15:50:41Z</dc:date>
    <item>
      <title>Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399239#M66609</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a unfriendly text file like below：&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Math Exam&lt;BR /&gt;Student Report&lt;BR /&gt;Calculus I&lt;BR /&gt;Fall 2016&lt;BR /&gt;Student: Eric&lt;BR /&gt;ID: 1234567&lt;BR /&gt;Date of Birth: 7/1/1990&lt;BR /&gt;Grade: 95&lt;BR /&gt;Report Date: 12/20/2016&lt;BR /&gt;School: 123 Edison&lt;BR /&gt;District: 123 Edison&lt;/P&gt;&lt;P&gt;Description : This is an easy exam&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Math Exam&lt;BR /&gt;Student Report&lt;BR /&gt;Calculus I&lt;BR /&gt;Fall 2016&lt;BR /&gt;Student: Amy&lt;BR /&gt;ID: 1234519&lt;BR /&gt;Date of Birth: 12/18/1990&lt;BR /&gt;Grade: 77&lt;BR /&gt;Report Date: 12/20/2016&lt;BR /&gt;School: 123 Edison&lt;BR /&gt;District: 123 Edison&lt;/P&gt;&lt;P&gt;Description : This is a real tough exam&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Math Exam&lt;BR /&gt;Student Report&lt;BR /&gt;Calculus I&lt;BR /&gt;Fall 2016&lt;BR /&gt;Student: John&lt;BR /&gt;ID: 1234569&lt;BR /&gt;Date of Birth: 3/1/1991&lt;BR /&gt;Grade: 90&lt;BR /&gt;Report Date: 12/20/2016&lt;BR /&gt;School: 123 Edison&lt;BR /&gt;District: 123 Edison&lt;/P&gt;&lt;P&gt;Description : This is an easy exam&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Math Exam&lt;BR /&gt;Student Report&lt;BR /&gt;Calculus I&lt;BR /&gt;Fall 2016&lt;BR /&gt;Student: Ava&lt;BR /&gt;ID: 1234523&lt;BR /&gt;Date of Birth: 9/13/1992&lt;BR /&gt;Grade: 89&lt;BR /&gt;Report Date: 12/20/2016&lt;BR /&gt;School: 123 Edison&lt;BR /&gt;District: 123 Edison&lt;/P&gt;&lt;P&gt;Description : This is a not a hard exam&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;－－－－－－－－－－－－－－－－－－－－－－－－－－－－&lt;/P&gt;&lt;P&gt;I have read tons of papers to extract data from text file, like&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-text-file/td-p/278012" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-text-file/td-p/278012&lt;/A&gt;. I tried their ways, &amp;nbsp;but still have no idea how to extract&lt;/P&gt;&lt;P&gt;1 course name&lt;/P&gt;&lt;P&gt;2 student name&lt;/P&gt;&lt;P&gt;3 student id number&amp;nbsp;&lt;/P&gt;&lt;P&gt;4 student date of birth&amp;nbsp;&lt;/P&gt;&lt;P&gt;5 grade&lt;/P&gt;&lt;P&gt;6 report date&amp;nbsp;&lt;/P&gt;&lt;P&gt;from such text file, can anyone please help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;－－－－－－－－－－－－－－－－－－－&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;my final goal is to obtain a dataset like below&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Calculus I &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;Eric &amp;nbsp; 1234567 &amp;nbsp;7/1/1990 &amp;nbsp; &amp;nbsp; &amp;nbsp; 95 12/20/2016&lt;/P&gt;&lt;P&gt;Calculus I &amp;nbsp; Amy &amp;nbsp;1234519 &amp;nbsp;12/18/1990 &amp;nbsp; 77 12/20/2016&lt;/P&gt;&lt;P&gt;Calculus I &amp;nbsp; John &amp;nbsp;1234569 &amp;nbsp;3/1/1991 &amp;nbsp; &amp;nbsp; &amp;nbsp;90 12/20/2016&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Calculus I &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Ava &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;1234523 &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;9/13/1992 &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;89&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;12/20/2016&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 15:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399239#M66609</guid>
      <dc:creator>Wei2017</dc:creator>
      <dc:date>2017-09-28T15:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399242#M66610</link>
      <description>&lt;P&gt;Do the rows repeat at all, or are you reading a single record from a file?&lt;/P&gt;
&lt;P&gt;I think you need to provide more information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can read from a multi lines in SAS using an INPUT statement.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 15:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399242#M66610</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-27T15:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399262#M66611</link>
      <description>&lt;P&gt;Hi, I add more detailed information about this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are multiple students in the text file. I listed four students just as an example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 17:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399262#M66611</guid>
      <dc:creator>Wei2017</dc:creator>
      <dc:date>2017-09-27T17:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399280#M66612</link>
      <description>&lt;P&gt;Here's the mechanism for how you'd do this:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/code/reading-a-multiple-line-per-subject-data-file/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/code/reading-a-multiple-line-per-subject-data-file/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you've tried something make sure to include it, otherwise that will likely be the&amp;nbsp;first suggestion you get and it's a waste of everyones time.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 17:49:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399280#M66612</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-27T17:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399313#M66613</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; That's an excellent reference.&amp;nbsp; Saving that in case i need it!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;@@&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/167312"&gt;@Wei2017&lt;/a&gt;&amp;nbsp; That text looks a lot like the structure of an XML document without the tags.&amp;nbsp; If whereever you are getting that text dump from could give you that as XML instead, it might read easier. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;exam_record&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;examtype&amp;gt;Math&amp;lt;/examtype&amp;gt;&lt;BR /&gt;&amp;lt;reporttype&amp;gt;Student&amp;lt;/reporttype&amp;gt;&lt;BR /&gt;&amp;lt;subject&amp;gt;Calculus I&amp;lt;/subject&amp;gt;&lt;BR /&gt;&amp;lt;date&amp;gt;Fall 2016&amp;lt;/date&amp;gt;&lt;BR /&gt;&amp;lt;studentname&amp;gt;Eric&amp;lt;/studentname&amp;gt;&lt;BR /&gt;&amp;lt;studentid&amp;gt;1234567&amp;lt;/studentid&amp;gt;&lt;BR /&gt;&amp;lt;dob&amp;gt;7/1/1990&amp;lt;/dob&amp;gt;&lt;BR /&gt;&amp;lt;grade&amp;gt;95&amp;lt;/grade&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;reportdate&amp;gt;12/20/2016&amp;lt;/reportdate&amp;gt;&lt;BR /&gt;&amp;lt;school&amp;gt;123 Edison&amp;lt;/school&amp;gt;&lt;BR /&gt;&amp;lt;district&amp;gt;123 Edison&amp;lt;/district&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;description&amp;gt;This is an easy exam&amp;lt;/description&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;lt;/exam_record&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 19:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399313#M66613</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-09-27T19:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399315#M66614</link>
      <description>&lt;P&gt;Can you explain "&lt;SPAN&gt;The expected results like below :" further? Do you need a dataset, a report in the posted format, the result printed in the log?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 19:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399315#M66614</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-09-27T19:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399330#M66616</link>
      <description>&lt;P&gt;Yes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;my final goal is to obtain a dataset like below&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Calculus I &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;Eric &amp;nbsp; 1234567 &amp;nbsp;7/1/1990 &amp;nbsp; &amp;nbsp; &amp;nbsp; 95 12/20/2016&lt;/P&gt;&lt;P&gt;Calculus I &amp;nbsp; Amy &amp;nbsp;1234519 &amp;nbsp;12/18/1990 &amp;nbsp; 77 12/20/2016&lt;/P&gt;&lt;P&gt;Calculus I &amp;nbsp; John &amp;nbsp;1234569 &amp;nbsp;3/1/1991 &amp;nbsp; &amp;nbsp; &amp;nbsp;90 12/20/2016&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Calculus I &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Ava &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;1234523 &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;9/13/1992 &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;89&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;12/20/2016&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have tried example like&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-text-file/td-p/278012" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-text-file/td-p/278012&lt;/A&gt;, but still have no idea how to deal with this one. Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 20:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399330#M66616</guid>
      <dc:creator>Wei2017</dc:creator>
      <dc:date>2017-09-27T20:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399331#M66617</link>
      <description>&lt;P&gt;Thank you for your link, but that is not what i am looking for.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-text-file/td-p/278012" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-text-file/td-p/278012&lt;/A&gt;, it is a little bit similar to my question.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 20:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399331#M66617</guid>
      <dc:creator>Wei2017</dc:creator>
      <dc:date>2017-09-27T20:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399332#M66618</link>
      <description>&lt;P&gt;The link posted by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;has exactly what you need to solve the issue. One obersavation in your requested output dataset has the data of multiple lines from your source file.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 20:28:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399332#M66618</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-09-27T20:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399350#M66622</link>
      <description>&lt;P&gt;EDIT:&amp;nbsp; I don't know why this answer formatted this way, with no breaks in the SAS code and a scroll on the last piece of text.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given a text file like:&lt;/P&gt;
&lt;PRE&gt;Math Exam
Student Report
Calculus I
Fall 2016
Student: Eric
ID: 1234567
Date of Birth: 7/1/1990
Grade: 95
Report Date: 12/20/2016
School: 123 Edison
District: 123 Edison
Description : This is an easy exam
Math Exam
Student Report
Calculus I
Fall 2016
Student: Amy
ID: 1234519
Date of Birth: 12/18/1990
Grade: 77
Report Date: 12/20/2016
School: 123 Edison
District: 123 Edison
Description : This is a real tough exam
Math Exam
Student Report
Calculus I
Fall 2016
Student: John
ID: 1234569
Date of Birth: 3/1/1991
Grade: 90
Report Date: 12/20/2016
School: 123 Edison
District: 123 Edison
Description : This is an easy exam
Math Exam
Student Report
Calculus I
Fall 2016
Student: Ava
ID: 1234523
Date of Birth: 9/13/1992
Grade: 89
Report Date: 12/20/2016
School: 123 Edison
District: 123 Edison
Description : This is a not a hard exam&lt;/PRE&gt;
&lt;P&gt;SAS code like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data incoming_text;
infile 'J:\some location where your file is\unfriendly_text_file.txt';
input 
exam_type &amp;amp; $20.

#2 report_type &amp;amp; $20.

#3 subject &amp;amp; $20.

#4 mydate &amp;amp; $20.
#5 @10 student &amp;amp; $20.
#6 @5 id &amp;amp; $20.
#7 @16 dob &amp;amp; $20.
#8 @8 grade &amp;amp; $20.
#9 @14 reportdate &amp;amp; $20.
#10 @9 school &amp;amp; $20.
#11 @11 district &amp;amp; $20.
#12 @15 description &amp;amp; $45
.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will give you&lt;/P&gt;
&lt;TABLE width="940"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;exam_type&lt;/TD&gt;
&lt;TD width="102"&gt;report_type&lt;/TD&gt;
&lt;TD width="65"&gt;subject&lt;/TD&gt;
&lt;TD width="60"&gt;mydate&lt;/TD&gt;
&lt;TD width="55"&gt;student&lt;/TD&gt;
&lt;TD width="56"&gt;id&lt;/TD&gt;
&lt;TD width="75"&gt;dob&lt;/TD&gt;
&lt;TD width="42"&gt;grade&lt;/TD&gt;
&lt;TD width="75"&gt;reportdate&lt;/TD&gt;
&lt;TD width="72"&gt;school&lt;/TD&gt;
&lt;TD width="72"&gt;district&lt;/TD&gt;
&lt;TD width="161"&gt;description&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;Math Exam&lt;/TD&gt;
&lt;TD width="102"&gt;Student Report&lt;/TD&gt;
&lt;TD width="65"&gt;Calculus I&lt;/TD&gt;
&lt;TD width="60"&gt;Fall 2016&lt;/TD&gt;
&lt;TD width="55"&gt;Eric&lt;/TD&gt;
&lt;TD width="56"&gt;1234567&lt;/TD&gt;
&lt;TD width="75"&gt;7/1/1990&lt;/TD&gt;
&lt;TD width="42"&gt;95&lt;/TD&gt;
&lt;TD width="75"&gt;12/20/2016&lt;/TD&gt;
&lt;TD width="72"&gt;123 Edison&lt;/TD&gt;
&lt;TD width="72"&gt;123 Edison&lt;/TD&gt;
&lt;TD width="161"&gt;This is an easy exam&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;Math Exam&lt;/TD&gt;
&lt;TD width="102"&gt;Student Report&lt;/TD&gt;
&lt;TD width="65"&gt;Calculus I&lt;/TD&gt;
&lt;TD width="60"&gt;Fall 2016&lt;/TD&gt;
&lt;TD width="55"&gt;Amy&lt;/TD&gt;
&lt;TD width="56"&gt;1234519&lt;/TD&gt;
&lt;TD width="75"&gt;12/18/1990&lt;/TD&gt;
&lt;TD width="42"&gt;77&lt;/TD&gt;
&lt;TD width="75"&gt;12/20/2016&lt;/TD&gt;
&lt;TD width="72"&gt;123 Edison&lt;/TD&gt;
&lt;TD width="72"&gt;123 Edison&lt;/TD&gt;
&lt;TD width="161"&gt;This is a real tough exam&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;Math Exam&lt;/TD&gt;
&lt;TD width="102"&gt;Student Report&lt;/TD&gt;
&lt;TD width="65"&gt;Calculus I&lt;/TD&gt;
&lt;TD width="60"&gt;Fall 2016&lt;/TD&gt;
&lt;TD width="55"&gt;John&lt;/TD&gt;
&lt;TD width="56"&gt;1234569&lt;/TD&gt;
&lt;TD width="75"&gt;3/1/1991&lt;/TD&gt;
&lt;TD width="42"&gt;90&lt;/TD&gt;
&lt;TD width="75"&gt;12/20/2016&lt;/TD&gt;
&lt;TD width="72"&gt;123 Edison&lt;/TD&gt;
&lt;TD width="72"&gt;123 Edison&lt;/TD&gt;
&lt;TD width="161"&gt;This is an easy exam&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;Math Exam&lt;/TD&gt;
&lt;TD width="102"&gt;Student Report&lt;/TD&gt;
&lt;TD width="65"&gt;Calculus I&lt;/TD&gt;
&lt;TD width="60"&gt;Fall 2016&lt;/TD&gt;
&lt;TD width="55"&gt;Ava&lt;/TD&gt;
&lt;TD width="56"&gt;1234523&lt;/TD&gt;
&lt;TD width="75"&gt;9/13/1992&lt;/TD&gt;
&lt;TD width="42"&gt;89&lt;/TD&gt;
&lt;TD width="75"&gt;12/20/2016&lt;/TD&gt;
&lt;TD width="72"&gt;123 Edison&lt;/TD&gt;
&lt;TD width="72"&gt;123 Edison&lt;/TD&gt;
&lt;TD width="161"&gt;This is a not a hard exam&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&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;You can mess around with the read&amp;nbsp; instructions and read only the lines you want or just read everything and drop the variables you don't want.&amp;nbsp; You can also read things properly as dates and numbers and not generic character variables of length 20 as I have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe like&lt;/P&gt;
&lt;P&gt;#6 @5 id &amp;amp; 7.&lt;BR /&gt;#7 @16 dob:mmddyy10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 03:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399350#M66622</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-09-28T03:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399358#M66623</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/6401"&gt;@HB&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;can mess around with the read&amp;nbsp; instructions and read only the lines you want or just read everything and drop the variables you don't want.&amp;nbsp; You can also read things properly as dates and numbers and not generic character variables of length 20 as I have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe like&lt;/P&gt;
&lt;P&gt;@#6 @5 id &amp;amp; 7.&lt;BR /&gt;@#7 @16 dob:mmddyy10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116880"&gt;@one&lt;/a&gt; of the other options for the read at is to read at a text value such as: #6&amp;nbsp;@'Student:'&amp;nbsp; and you don't even have to count the characters. I have to say that I found the mixture of some sort of row header, such as Student, ID, Date of Birth and three rows without them odd.&lt;/P&gt;
&lt;P&gt;One concern is the first example file has varying numbers of blank lines after Description so there may need to be some code to resync between records if the actual data has that behavior. There may also have to be something to deal with a description that runs to two or more lines but &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/167312"&gt;@Wei2017&lt;/a&gt;&amp;nbsp;hasn't specified if that happens.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 22:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399358#M66623</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-27T22:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399387#M66624</link>
      <description>&lt;P&gt;If you don't post what you've tried then you're going to get suggestions that may not work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And it should work so you're likely doing something wrong, but we can't tell you since you haven't shown us any code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or if you did do it correctly it would give us something to start with rather than starting from scratch.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/167312"&gt;@Wei2017&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for your link, but that is not what i am looking for.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-text-file/td-p/278012" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-text-file/td-p/278012&lt;/A&gt;, it is a little bit similar to my question.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 03:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399387#M66624</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-28T03:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399391#M66625</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/6401"&gt;@HB&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;EDIT:&amp;nbsp; I don't know why this answer formatted this way, with no breaks in the SAS code and a scroll on the last piece of text.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do not edit the text in the code block in the normal editor. Instead place the cursor in the block and click the menu bar icon and edit the code block in the pop-up window.&amp;nbsp; If you edit it directly in the main editor window it loses the special formatting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add the TRUNCOVER option to your INFILE statement and then you don't need those &amp;amp;'s and :'s in the INPUT statement.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 03:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399391#M66625</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-28T03:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399397#M66626</link>
      <description>&lt;P&gt;Your file looks pretty tame. I am worried because it does not appear to have the same number of lines for each "record".&amp;nbsp; Does that mean that also does not always have every type of line?&amp;nbsp; If it is regular then just read the fields directly.&amp;nbsp; You can use # to / in your INPUT statement (or just use multiple INPUT statements).&amp;nbsp; So if every record had exactly 14 lines you could do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile 'myfile.txt' n=14 truncover ;
input 
#3 course $30.
#5 @':' student $30.
#6 @':' id 
#7 @':' dob mmddyy12. 
#8 @':' grade
#9 @':' repdate  mmddyy12.
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if the randomness is just in the number of blank lines between groups then you could instead add a little more logic an flexibility by looking for some text that signals the start of a new "record".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile 'myfile.txt' truncover ;
input @;
if _infile_ = 'Math Exam' then do ;
input 
// course $30.
// @':' student $30.
 / @':' id 
 / @':' dob mmddyy12. 
 / @':' grade
 / @':' repdate  mmddyy12.
;
output;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If it is really messy then you need to read each record type separately and retain the values and execute the OUTPUT statement when you get to the end of the "record" .&amp;nbsp; Or perhaps when you start another record or hit the end of the file.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 435px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15474i5166958063539193/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try something like one of the above on your real file and report back.&amp;nbsp; (Note make sure to add the missing statements to make a complete data step and don't forget to add FORMAT statements for your date variables).&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 04:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399397#M66626</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-28T04:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399500#M66638</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;Do not edit the text in the code block in the normal editor. Instead place the cursor in the block and click the menu bar icon and edit the code block in the pop-up window.&amp;nbsp; If you edit it directly in the main editor window it loses the special formatting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add the TRUNCOVER option to your INFILE statement and then you don't need those &amp;amp;'s and :'s in the INPUT statement.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!! Cool!!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 14:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399500#M66638</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-09-28T14:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399501#M66639</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 14:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399501#M66639</guid>
      <dc:creator>Wei2017</dc:creator>
      <dc:date>2017-09-28T14:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399503#M66640</link>
      <description>&lt;P&gt;Thank you. The original text file is far more complex than that i provided. You code gives me a hint to deal with that unfriendly text file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 14:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399503#M66640</guid>
      <dc:creator>Wei2017</dc:creator>
      <dc:date>2017-09-28T14:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399525#M66643</link>
      <description>&lt;P&gt;Apologise for not posting my code and result part.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/6401"&gt;@HB&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43025"&gt;@error_prone&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code and what i get in sas:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Result.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15483i264CE00D69ADB93F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Result.png" alt="Result.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data temp;
infile 'exam.txt';
retain Course StudentName Grade Reportdate ID School DoB District;
input;
if _infile_ =: 'Calculus' then Course = scan(_infile_, 1, '\\');
  else if _infile_ =: 'Student' then StudentName = scan(_infile_, -1, ':');
   else if _infile_ =: 'ID' then ID = scan(_infile_, -1, ':');
    else if _infile_ =: 'Grade' then Grade = scan(_infile_, -1, ':');
     else if _infile_ =: 'Date of Birth' then Dob = scan(_infile_, -1, ':');
      else if _infile_ =: 'School' then School = scan(_infile_, -1, ':');
       else if _infile_ =: 'District' then District = scan(_infile_, -1, ':');
          else if (_infile_)=:'Report Date' then do 
            Reportdate = scan(_infile_,-1,':');
         output;
         end;
run;

proc print data = temp;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am still get lost in sas.&lt;/P&gt;&lt;P&gt;(1) Why is there something missing in the first row?&lt;/P&gt;&lt;P&gt;(2) How to convert Reportdate format into mmddyy? eg convert 12/20/2016 to 12/20/16&lt;/P&gt;&lt;P&gt;(3) Is there some ways that could split School into School code and School name?&amp;nbsp; eg "123 Edision" into "123" and "Edison"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your time reading this.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 15:26:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399525#M66643</guid>
      <dc:creator>Wei2017</dc:creator>
      <dc:date>2017-09-28T15:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399531#M66645</link>
      <description>&lt;P&gt;Define your variables. Don't force SAS to guess what you meant them to be by how they first appear in the code.&lt;/P&gt;
&lt;P&gt;Don't bother with all of those nested IF/THEN statements. Let the natural SAS processing do that work for you. Take advantage of the power of the INPUT statement.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
  infile 'exam.txt' truncover dsd dlm=':';
  length Course $30 StudentName $30 Grade Reportdate 8 ID $10 SchoolCode $8 School $30 DoB 8 District $30 ;
  format ReportDate DoB mmddyy10. ;
  retain Course -- District; 
  length chk $100 ;
  input chk @; 
  if chk = 'Calculus' then input Course ;
  if chk = 'Student' then input StudentName ;
  if chk = 'ID' then input ID ;
  if chk = 'Grade' then input Grade ;
  if chk = 'Date of Birth' then input Dob mmddyy12. ;
  if chk = 'School' then input School ;
  if chk = 'District' then input District ;
  if chk ='Report Date' then do; 
    input Reportdate mmddyy12. ;
    schoolcode =scan(school,1,' ');
    school = substr(school,length(schoolcode)+2);
    output;
    call missing(of _all_);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that SAS can normally read date values with 2 digit years and make the right choice is to what century is meant, but why would want to print your dates without the century?&amp;nbsp; You are just inviting trouble later.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 15:50:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399531#M66645</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-28T15:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from a unfriendly text file</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399604#M66654</link>
      <description>&lt;P&gt;Thank you for your code and exmplanation. The code is so awesome. I impleneted in my jupyter notebook, why some part is still missing like SchoolCode for Eric?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Result_1.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15488iB16551C624B4A117/image-size/large?v=v2&amp;amp;px=999" role="button" title="Result_1.png" alt="Result_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extract-data-from-a-unfriendly-text-file/m-p/399604#M66654</guid>
      <dc:creator>Wei2017</dc:creator>
      <dc:date>2017-09-28T20:57:09Z</dc:date>
    </item>
  </channel>
</rss>

