<?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: Convert complex text file to sas dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-complex-text-file-to-sas-dataset/m-p/624127#M183798</link>
    <description>&lt;P&gt;This is a primitive description method. How about the following program?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename get "c:\temp\sampledata.txt";
data worktable;
  length RepName $80
         AppNo $10
         AppName $16
         DOPRNT 8
         Branch 8
         Address1 $80
         Address2 $80
         Address3 $80
         Gender $1 
         Marital $1 
         IDNo $10 
         DOB 8
         DOPRCS 8
         AppDate 8
         Page 8
         n 8
         ;
  format 
         DOPRNT mmddyy10.
         DOB mmddyy10.
         DOPRCS mmddyy10.
         AppDate mmddyy10.
         ;
  array pos{3} 8;
  retain _all_;
  infile get;

  input;
  n=_n_;
  if find(_infile_,"Report Name:",'i')=1 then do;
    call missing(RepName);
    call missing(AppNo);
    call missing(AppName);
    call missing(DOPRNT);
    call missing(Branch);
    call missing(Address1);
    call missing(Address2);
    call missing(Address3);
    call missing(Gender);
    call missing(Marital);
    call missing(IDNo);
    call missing(DOB);
    call missing(DOPRCS);
    call missing(Page);
    pos1=length("Report Name:");
    pos2=find(_infile_,"Date printed:",'i');
    pos3=length("Date printed:");
    RepName=strip(substr(_infile_
                        ,pos1+1
                        ,pos2-pos1-1));
    if pos2&amp;gt;1 then do;
      DOPRNT=input(strip(substr(_infile_,pos2+pos3,10)),ddmmyy10.);
    end;
    
    pos2=find(_infile_,"Page:",'i');
    pos3=length("Page:");
    if pos2&amp;gt;1 then do;
      Page=input(strip(substr(_infile_,pos2+pos3)),best.);
    end;
  end;else
  if find(_infile_,"Branch:",'i')&amp;gt;1 then do;
    pos2=find(_infile_,"Branch:",'i');
    pos3=length("Branch:");
    Branch=input(strip(substr(_infile_,pos2+pos3,12)),best.);
    
    pos2=find(_infile_,"Process Date:",'i');
    pos3=length("Process Date:");
    if pos2&amp;gt;1 then do;
      DOPRCS=input(strip(substr(_infile_,pos2+pos3,10)),ddmmyy10.);
    end;
  end;else
  if find(_infile_,"Application No:",'i')=1 then do;
    AppNo=strip(substr(_infile_,length("Application No:")+1));
  end;else
  if find(_infile_,"Application Name:",'i')=1 then do;
    AppName=strip(substr(_infile_,length("Application Name:")+1));
  end;else
  if find(_infile_,"Application Date:",'i')=1 then do;
    AppDate=input(strip(substr(_infile_,length("Application Date:")+1)),ddmmyy10.);
  end;else
  if find(_infile_,"Gender:",'i')=1 then do;

    pos1=length("Gender:");
    pos2=find(_infile_,"ID No:",'i');
    pos3=length("ID No:");

    Gender=strip(substr(_infile_,pos1+1,pos2-1));
    IDNo=strip(substr(_infile_,pos2+pos3));
  end;else
  if find(_infile_,"Marital Status:",'i')=1 then do;

    pos1=length("Marital Status:");
    pos2=find(_infile_,"DOB:",'i');
    pos3=length("DOB:");

    Marital=strip(substr(_infile_,pos1+1,pos2-1));
    DOB=input(strip(substr(_infile_,pos2+pos3)),mmddyy10.);
  end;else
  if find(_infile_,"Address 1:",'i')=1 then do;
    Address1=strip(substr(_infile_,length("Address 1:")+1));
  end;else
  if find(_infile_," 2:",'i')&amp;gt;1 then do;
    pos2=find(_infile_," 2:",'i');
    pos3=length(" 2:");
    Address2=strip(substr(_infile_,pos2+pos3));
  end;else
  if find(_infile_," 3:",'i')&amp;gt;1 then do;
    pos2=find(_infile_," 3:",'i');
    pos3=length(" 3:");
    Address3=strip(substr(_infile_,pos2+pos3));
  end;
  drop pos:;
run;
proc sort data=worktable;
  by n page;
run;
data get;
  set worktable;
  by page;
  if last.page;
  drop n;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 12 Feb 2020 09:42:07 GMT</pubDate>
    <dc:creator>japelin</dc:creator>
    <dc:date>2020-02-12T09:42:07Z</dc:date>
    <item>
      <title>Convert complex text file to sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-complex-text-file-to-sas-dataset/m-p/624097#M183781</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone can help to solve my problem? i have daily text files with 2k+ pages and i need to capture all fields in the txt file i.e&lt;/P&gt;&lt;P&gt;Application no, Application Name, Branch, Address 1, 2 ,3, Gender, Marital Status, ID No, DOB, Application Date, Page.&lt;/P&gt;&lt;P&gt;All these fields need to be convert to SAS dataset and the process will need to be repeat until last pages.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sample data&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Report Name: Personal Information&amp;nbsp; Date printed:12/02/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Page:1&lt;/P&gt;&lt;P&gt;XYZ Enterprise&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Branch:100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Process Date:12/02/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Application No:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1234567890&lt;/P&gt;&lt;P&gt;Application Name:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; XxYyyZzz AAA BBB&lt;/P&gt;&lt;P&gt;Address 1:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1, Xmas street 2,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;New York&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;USA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Report Name: Personal Information&amp;nbsp; Date printed:12/02/2020&amp;nbsp;&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Page:2&lt;/P&gt;&lt;P&gt;XYZ Enterprise&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Branch:100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Process Date:12/02/2020&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Gender:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;F&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ID No:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;987654321&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Marital Status:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DOB:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 03/03/1967&lt;/SPAN&gt;&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;Report Name: Personal Information&amp;nbsp; Date printed:12/02/2020&amp;nbsp;&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Page:3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;XYZ Enterprise&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Branch:100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Process Date:12/02/2020&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Application Date:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03/12/2019&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 07:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-complex-text-file-to-sas-dataset/m-p/624097#M183781</guid>
      <dc:creator>KLMQ</dc:creator>
      <dc:date>2020-02-12T07:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Convert complex text file to sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-complex-text-file-to-sas-dataset/m-p/624127#M183798</link>
      <description>&lt;P&gt;This is a primitive description method. How about the following program?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename get "c:\temp\sampledata.txt";
data worktable;
  length RepName $80
         AppNo $10
         AppName $16
         DOPRNT 8
         Branch 8
         Address1 $80
         Address2 $80
         Address3 $80
         Gender $1 
         Marital $1 
         IDNo $10 
         DOB 8
         DOPRCS 8
         AppDate 8
         Page 8
         n 8
         ;
  format 
         DOPRNT mmddyy10.
         DOB mmddyy10.
         DOPRCS mmddyy10.
         AppDate mmddyy10.
         ;
  array pos{3} 8;
  retain _all_;
  infile get;

  input;
  n=_n_;
  if find(_infile_,"Report Name:",'i')=1 then do;
    call missing(RepName);
    call missing(AppNo);
    call missing(AppName);
    call missing(DOPRNT);
    call missing(Branch);
    call missing(Address1);
    call missing(Address2);
    call missing(Address3);
    call missing(Gender);
    call missing(Marital);
    call missing(IDNo);
    call missing(DOB);
    call missing(DOPRCS);
    call missing(Page);
    pos1=length("Report Name:");
    pos2=find(_infile_,"Date printed:",'i');
    pos3=length("Date printed:");
    RepName=strip(substr(_infile_
                        ,pos1+1
                        ,pos2-pos1-1));
    if pos2&amp;gt;1 then do;
      DOPRNT=input(strip(substr(_infile_,pos2+pos3,10)),ddmmyy10.);
    end;
    
    pos2=find(_infile_,"Page:",'i');
    pos3=length("Page:");
    if pos2&amp;gt;1 then do;
      Page=input(strip(substr(_infile_,pos2+pos3)),best.);
    end;
  end;else
  if find(_infile_,"Branch:",'i')&amp;gt;1 then do;
    pos2=find(_infile_,"Branch:",'i');
    pos3=length("Branch:");
    Branch=input(strip(substr(_infile_,pos2+pos3,12)),best.);
    
    pos2=find(_infile_,"Process Date:",'i');
    pos3=length("Process Date:");
    if pos2&amp;gt;1 then do;
      DOPRCS=input(strip(substr(_infile_,pos2+pos3,10)),ddmmyy10.);
    end;
  end;else
  if find(_infile_,"Application No:",'i')=1 then do;
    AppNo=strip(substr(_infile_,length("Application No:")+1));
  end;else
  if find(_infile_,"Application Name:",'i')=1 then do;
    AppName=strip(substr(_infile_,length("Application Name:")+1));
  end;else
  if find(_infile_,"Application Date:",'i')=1 then do;
    AppDate=input(strip(substr(_infile_,length("Application Date:")+1)),ddmmyy10.);
  end;else
  if find(_infile_,"Gender:",'i')=1 then do;

    pos1=length("Gender:");
    pos2=find(_infile_,"ID No:",'i');
    pos3=length("ID No:");

    Gender=strip(substr(_infile_,pos1+1,pos2-1));
    IDNo=strip(substr(_infile_,pos2+pos3));
  end;else
  if find(_infile_,"Marital Status:",'i')=1 then do;

    pos1=length("Marital Status:");
    pos2=find(_infile_,"DOB:",'i');
    pos3=length("DOB:");

    Marital=strip(substr(_infile_,pos1+1,pos2-1));
    DOB=input(strip(substr(_infile_,pos2+pos3)),mmddyy10.);
  end;else
  if find(_infile_,"Address 1:",'i')=1 then do;
    Address1=strip(substr(_infile_,length("Address 1:")+1));
  end;else
  if find(_infile_," 2:",'i')&amp;gt;1 then do;
    pos2=find(_infile_," 2:",'i');
    pos3=length(" 2:");
    Address2=strip(substr(_infile_,pos2+pos3));
  end;else
  if find(_infile_," 3:",'i')&amp;gt;1 then do;
    pos2=find(_infile_," 3:",'i');
    pos3=length(" 3:");
    Address3=strip(substr(_infile_,pos2+pos3));
  end;
  drop pos:;
run;
proc sort data=worktable;
  by n page;
run;
data get;
  set worktable;
  by page;
  if last.page;
  drop n;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Feb 2020 09:42:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-complex-text-file-to-sas-dataset/m-p/624127#M183798</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2020-02-12T09:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert complex text file to sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-complex-text-file-to-sas-dataset/m-p/624237#M183864</link>
      <description>&lt;P&gt;Please paste examples of a text file into a code box opened on the forum with the {I} icon. The main message windows &lt;STRONG&gt;will&lt;/STRONG&gt; reformat pasted text to remove certain forms of white space and may insert HTML tags that make the text quite different than is actually in your file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should also include a minimum of two complete records, three would be better.&lt;/P&gt;
&lt;P&gt;Describe exactly how we know that the block of data is for a new record or the end of a record.&lt;/P&gt;
&lt;P&gt;Is there a standard number of lines that each record occupies or is it variable? If this content varies then you &lt;STRONG&gt;really&lt;/STRONG&gt;&amp;nbsp;need to show examples of different layouts. Since you show a field labeled "Report Name " I am very concerned that there might be other reports in the same file with different layout.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It also would help to provide&lt;/P&gt;
&lt;P&gt;1) expected variable names to create&lt;/P&gt;
&lt;P&gt;2) properties for the variables such as maximum length&lt;/P&gt;
&lt;P&gt;3) which repeated pieces of information shown need to be in the resulting data such as Report Name, Date Printed or Page number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 16:24:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-complex-text-file-to-sas-dataset/m-p/624237#M183864</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-12T16:24:04Z</dc:date>
    </item>
  </channel>
</rss>

