<?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: importing a txt-file correctly in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199487#M266699</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman';"&gt;Write a SAS program that reads the new file&amp;nbsp; LRECL=8400.&amp;nbsp; Define 100 variables, each 84 characters long.&amp;nbsp; Output&amp;nbsp; each variable 84 characters long (do loop 100 times) to a TXT file. Then read that TXT file with your current program.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 09 Jul 2015 10:28:19 GMT</pubDate>
    <dc:creator>Jim_G</dc:creator>
    <dc:date>2015-07-09T10:28:19Z</dc:date>
    <item>
      <title>importing a txt-file correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199483#M266695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having a problem with importing a TXT file correctly.&lt;/P&gt;&lt;P&gt;Normally, the file has a lot of lines with each 84 characters. = 1 record&lt;/P&gt;&lt;P&gt;With the code I have here-under, I can perfectly import the text-file as I want. (one line = 1 record)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, I received an update of this TXT-file, and on each line, there are 8400 characters.&amp;nbsp;&amp;nbsp;&amp;nbsp; (one line = 100 records)&lt;/P&gt;&lt;P&gt;The second line start with record 101.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I use this code on this updated file, SAS only reads the first 84 characters on the first line and does not read characters 85-8400 on the first line, which are records 2-100.&lt;/P&gt;&lt;P&gt;It directly reads line 2 which contains record 101.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question:&amp;nbsp; how can I tell SAS to read character 85-169 as the second record, character 170-254 as the third record, etc&amp;nbsp; ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone has an idea?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------&lt;/P&gt;&lt;P&gt;%macro readOneFile(path_in=,file_in=,file_out=);&lt;/P&gt;&lt;P&gt;DATA &amp;amp;file_out.;&lt;BR /&gt; INFILE "&amp;amp;path_in.&amp;amp;file_in."&lt;BR /&gt; DSD DELIMITER=""&amp;nbsp; TRUNCOVER &lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;LENGTH &lt;BR /&gt;&amp;nbsp; var1 $ 5&lt;BR /&gt;&amp;nbsp; var2 $ 5&lt;BR /&gt;&amp;nbsp; var3 $ 3&lt;BR /&gt;&amp;nbsp; var4 $ 10&lt;BR /&gt;&amp;nbsp; var5 $ 10&lt;BR /&gt;&amp;nbsp; var6 8&lt;BR /&gt;&amp;nbsp; var7 8&lt;BR /&gt;&amp;nbsp; var8 8&lt;BR /&gt;&amp;nbsp; var9 8&lt;BR /&gt;&amp;nbsp; var10 8&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;INPUT&lt;BR /&gt;&amp;nbsp; @1 var1 $5.&lt;BR /&gt;&amp;nbsp; @6 var2 $5.&lt;BR /&gt;&amp;nbsp; @11 var3 $3.&lt;BR /&gt;&amp;nbsp; @14 var4 $10.&lt;BR /&gt;&amp;nbsp; @24 var5 $10.&lt;BR /&gt;&amp;nbsp; @34 var6 7.&lt;BR /&gt;&amp;nbsp; @41 var7 11.&lt;BR /&gt;&amp;nbsp; @52 var8 10.&lt;BR /&gt;&amp;nbsp; @62 var9 12.&lt;BR /&gt;&amp;nbsp; @74 var10 11.&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;%mend fileread;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 09:24:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199483#M266695</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2015-07-09T09:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: importing a txt-file correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199484#M266696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try the lrecl option on the infile:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;infile "&amp;amp;path_in.&amp;amp;file_in." dsd truncover lrecl=32767&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;To be honest though, you should setup a data transfer document which details the structure of the file, otherwise there is nothing to stop them updating the file each time.&amp;nbsp; I would also suggest to use CSV, or XML structure for the file.&amp;nbsp; Made up file formats like this just make the data harder to access.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 09:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199484#M266696</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-07-09T09:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: importing a txt-file correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199485#M266697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for your answer.&lt;/P&gt;&lt;P&gt;I tried the lrecl=32767 option, but the result is the same:&lt;/P&gt;&lt;P&gt;- the first line in my table contains line 1 character 1-84 (=record 1)&lt;/P&gt;&lt;P&gt;- the second line in my table contains line 2 character 1-84 (= record 101)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;records 2 - 100 are not read by SAS. (which are on line 1 in the TXT)&lt;/P&gt;&lt;P&gt;Is there a way to tell SAS that each 85th character is the start of a new record?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 09:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199485#M266697</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2015-07-09T09:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: importing a txt-file correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199486#M266698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, its quite confusing.&amp;nbsp; Maybe post the file, or a sample thereof.&amp;nbsp; It does sound very much like you need to go back and get the file being sent converted into something resembling a more useful structure.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 10:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199486#M266698</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-07-09T10:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: importing a txt-file correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199487#M266699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman';"&gt;Write a SAS program that reads the new file&amp;nbsp; LRECL=8400.&amp;nbsp; Define 100 variables, each 84 characters long.&amp;nbsp; Output&amp;nbsp; each variable 84 characters long (do loop 100 times) to a TXT file. Then read that TXT file with your current program.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 10:28:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199487#M266699</guid>
      <dc:creator>Jim_G</dc:creator>
      <dc:date>2015-07-09T10:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: importing a txt-file correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199488#M266700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your answers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@RW9:&lt;/P&gt;&lt;P&gt;imagine you have a txt-file which contains on 1 line 840 characters, which represent 10 records/observations.&amp;nbsp; &lt;/P&gt;&lt;P&gt;SAS should read the first 84 characters and put them in a table as the first record.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Next it should read the next 84 characters (position 85 - 169) of the first line and put them in the table as the second record&lt;/P&gt;&lt;P&gt;Next it should read the next 84 characters (position 170 - 254) of the first line and put them in the table as the third record&lt;/P&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;Is this possible?&amp;nbsp; Or do I have to ask my source to alter the source file with only 84 characters per line?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@JIM&lt;/P&gt;&lt;P&gt;Just saw in the TXT-file that the end of line 1 and the beginning of line 2 contains each a part of the same record.&lt;/P&gt;&lt;P&gt;Guess it will become difficult to use that file.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 11:08:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199488#M266700</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2015-07-09T11:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: importing a txt-file correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199489#M266701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, its possible.&amp;nbsp; As Jim_G has mentioned.&amp;nbsp; In your import program, read the whole of line 1 into one variable.&amp;nbsp; Then do a loop over the line to output 10 sections:&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile xyz... lrecl=8400;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input the_full_line $;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to 10;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_var="";&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do j=1 to 84;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&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; out_var=strip(each_bit)||substr(the_full_line,(i-1 * 84)+j,1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Or something similar to the above.&amp;nbsp; This would read the whole text from line 1, then break it into 10 sections of 84 characters, and output.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I would still advise however to go with a better structure of datafile, setup a data import agreement, agree on a proper structure, would make your life easier in the long run.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 12:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199489#M266701</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-07-09T12:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: importing a txt-file correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199490#M266702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you all. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 12:10:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199490#M266702</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2015-07-09T12:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: importing a txt-file correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199491#M266703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use @@ at the end of INPUT .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 12:16:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199491#M266703</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-07-09T12:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: importing a txt-file correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199492#M266704</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;thanks xia, that's indeed what I needed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 13:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-a-txt-file-correctly/m-p/199492#M266704</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2015-07-09T13:45:12Z</dc:date>
    </item>
  </channel>
</rss>

