<?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 Invalid Data Error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Invalid-Data-Error/m-p/422449#M280891</link>
    <description>&lt;P&gt;Hello SAS Community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to read a number of .txt files into SAS.&lt;/P&gt;
&lt;P&gt;I am enclosing a sample of my data and a screenshot how the data end up in SAS.&lt;/P&gt;
&lt;P&gt;This is the code that I have used:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname lib 'E:\LSE_Tick1';

%let dirname = E:\LSE_Tick1;
filename DIRLIST pipe "dir /B &amp;amp;dirname\*.txt";
data dirlist ;
     length fname $256;
     infile dirlist length=reclen ;
     input fname $varying256. reclen ;
run;

data lib.LSE_tick (drop=fname);
  length myfilename $100;
  set dirlist;
  filepath = "&amp;amp;dirname\"||fname;
  infile dummy filevar = filepath length=reclen end=done DSD dlm= ' ' TRUNCOVER  firstobs=3; 
do while(not done); 
myfilename = filepath;
length TICode $12 TIDM $3 IssuerName $30 Cy $2 Cur $3 Segm $4 Sect $4 TT $2 I $1 TradeCode $10 SEDOL $7 P $1;
informat PublTstmp CancTstmp TradeTstmp datetime. ;
do until (done);
input TICode TIDM IssuerName Cy Cur Segm Sect PublTstmp CancTstmp TradeTstmp TradeSize TradePrice TT I TradeCode SEDOL P;
output;
end;
end;
drop myfilename;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After running the code, a list of error messages saying Invalid data for ...&amp;nbsp; in line ... on the log window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I look forward to your suggestions and thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sas Data.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17405i8FAE4F13F1AA374D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Sas Data.png" alt="Sas Data.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Dec 2017 19:18:51 GMT</pubDate>
    <dc:creator>BchBnz</dc:creator>
    <dc:date>2017-12-19T19:18:51Z</dc:date>
    <item>
      <title>Invalid Data Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Invalid-Data-Error/m-p/422449#M280891</link>
      <description>&lt;P&gt;Hello SAS Community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to read a number of .txt files into SAS.&lt;/P&gt;
&lt;P&gt;I am enclosing a sample of my data and a screenshot how the data end up in SAS.&lt;/P&gt;
&lt;P&gt;This is the code that I have used:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname lib 'E:\LSE_Tick1';

%let dirname = E:\LSE_Tick1;
filename DIRLIST pipe "dir /B &amp;amp;dirname\*.txt";
data dirlist ;
     length fname $256;
     infile dirlist length=reclen ;
     input fname $varying256. reclen ;
run;

data lib.LSE_tick (drop=fname);
  length myfilename $100;
  set dirlist;
  filepath = "&amp;amp;dirname\"||fname;
  infile dummy filevar = filepath length=reclen end=done DSD dlm= ' ' TRUNCOVER  firstobs=3; 
do while(not done); 
myfilename = filepath;
length TICode $12 TIDM $3 IssuerName $30 Cy $2 Cur $3 Segm $4 Sect $4 TT $2 I $1 TradeCode $10 SEDOL $7 P $1;
informat PublTstmp CancTstmp TradeTstmp datetime. ;
do until (done);
input TICode TIDM IssuerName Cy Cur Segm Sect PublTstmp CancTstmp TradeTstmp TradeSize TradePrice TT I TradeCode SEDOL P;
output;
end;
end;
drop myfilename;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After running the code, a list of error messages saying Invalid data for ...&amp;nbsp; in line ... on the log window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I look forward to your suggestions and thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sas Data.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17405i8FAE4F13F1AA374D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Sas Data.png" alt="Sas Data.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 19:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Invalid-Data-Error/m-p/422449#M280891</guid>
      <dc:creator>BchBnz</dc:creator>
      <dc:date>2017-12-19T19:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Data Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Invalid-Data-Error/m-p/422466#M280892</link>
      <description>&lt;P&gt;Hard to tell without downloading the attachment, but does your data have tabs between the fields?&lt;/P&gt;
&lt;P&gt;If so then make sure to tell the INFILE statement that.&amp;nbsp; It is best to use the hexcode for tab to prevent the editor from converting a quoted tab into a space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  infile dummy filevar = filepath length=reclen end=done DSD dlm= '09'x TRUNCOVER  firstobs=3; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If they are not tabs you will have trouble since there a then both many spaces between fields (make the DSD a problem) and embedded spaces in the values of some variables (making list mode in general a problem).&amp;nbsp; But it looks like your records are fixed width so just read it using the column locations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise show one or more example error messages from the LOG so we can see which variables for which variables it is not reading properly.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 19:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Invalid-Data-Error/m-p/422466#M280892</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-19T19:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Data Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Invalid-Data-Error/m-p/422480#M280893</link>
      <description>&lt;P&gt;Hello Tom,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks for your suggestion. It worked!!&lt;/P&gt;
&lt;P&gt;Just to understand, I assume&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;dlm&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'09'&lt;/SPAN&gt;x&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;stands for a tab?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, would you have any suggestions for the format of&amp;nbsp;date and time variable (e.g. 29/09/2017 07:15:05)? I tried creating the format but it did not work.&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 20:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Invalid-Data-Error/m-p/422480#M280893</guid>
      <dc:creator>BchBnz</dc:creator>
      <dc:date>2017-12-19T20:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Data Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Invalid-Data-Error/m-p/422495#M280894</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/7188"&gt;@BchBnz&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello Tom,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks for your suggestion. It worked!!&lt;/P&gt;
&lt;P&gt;Just to understand, I assume&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;dlm&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'09'&lt;/SPAN&gt;x&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;stands for a tab?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, would you have any suggestions for the format of&amp;nbsp;date and time variable (e.g. 29/09/2017 07:15:05)? I tried creating the format but it did not work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes. 9 is the hexcode for a tab.&amp;nbsp; '0A'x is a linefeed, '0D'x is a carriage return.&amp;nbsp; '20'x is a space, '30'x is the digit 0.&lt;/P&gt;
&lt;P&gt;Try using the ANYDTDTM informat for those dates.&amp;nbsp; If it doesn't work then read them as strings and split it into date and time strings and use INPUT() function to read each. You could then use DHMS() function to build a date time value from the results.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 20:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Invalid-Data-Error/m-p/422495#M280894</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-19T20:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Data Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Invalid-Data-Error/m-p/422500#M280895</link>
      <description>&lt;P&gt;Thank you ever so much for the explanation and suggestions, Tom!&lt;/P&gt;
&lt;P&gt;Much appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 21:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Invalid-Data-Error/m-p/422500#M280895</guid>
      <dc:creator>BchBnz</dc:creator>
      <dc:date>2017-12-19T21:15:36Z</dc:date>
    </item>
  </channel>
</rss>

