<?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 Importing large file, single variable to contain all info in record, new record at each &amp;quot;MSH|&amp;quot; chars in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522289#M141770</link>
    <description>&lt;P&gt;Hi all -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a large text file that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;MSH|askdasldkajs&lt;/P&gt;
&lt;P&gt;OBX|asdkjaslkj1239&lt;/P&gt;
&lt;P&gt;ORC|asdkljqoi3w4908&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MSH|asf98asfaslk&lt;/P&gt;
&lt;P&gt;OBX|asd8a7sdoaisyud&lt;/P&gt;
&lt;P&gt;NTE|asdasod7as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where I'd like each of those chunks (that start with MSH| and go to the location of the next MSH|) read into a single (large text) variable, and where each of the chunks would be it's own record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So basically, read through a text file, when encountering MSH|, dump everything (including the MSH|) into a single variable, then when it runs into the next MSH|, end that first record and start the second record with MSH|, etc. all the way to the end of the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone shine light on how to accomplish this? Thank you.&lt;/P&gt;</description>
    <pubDate>Tue, 18 Dec 2018 17:30:14 GMT</pubDate>
    <dc:creator>ucdcrush</dc:creator>
    <dc:date>2018-12-18T17:30:14Z</dc:date>
    <item>
      <title>Importing large file, single variable to contain all info in record, new record at each "MSH|" chars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522289#M141770</link>
      <description>&lt;P&gt;Hi all -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a large text file that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;MSH|askdasldkajs&lt;/P&gt;
&lt;P&gt;OBX|asdkjaslkj1239&lt;/P&gt;
&lt;P&gt;ORC|asdkljqoi3w4908&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MSH|asf98asfaslk&lt;/P&gt;
&lt;P&gt;OBX|asd8a7sdoaisyud&lt;/P&gt;
&lt;P&gt;NTE|asdasod7as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where I'd like each of those chunks (that start with MSH| and go to the location of the next MSH|) read into a single (large text) variable, and where each of the chunks would be it's own record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So basically, read through a text file, when encountering MSH|, dump everything (including the MSH|) into a single variable, then when it runs into the next MSH|, end that first record and start the second record with MSH|, etc. all the way to the end of the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone shine light on how to accomplish this? Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 17:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522289#M141770</guid>
      <dc:creator>ucdcrush</dc:creator>
      <dc:date>2018-12-18T17:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Importing large file, single variable to contain all info in record, new record at each "MS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522290#M141771</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34719"&gt;@ucdcrush&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a large text file that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;MSH|askdasldkajs&lt;/P&gt;
&lt;P&gt;OBX|asdkjaslkj1239&lt;/P&gt;
&lt;P&gt;ORC|asdkljqoi3w4908&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MSH|asf98asfaslk&lt;/P&gt;
&lt;P&gt;OBX|asd8a7sdoaisyud&lt;/P&gt;
&lt;P&gt;NTE|asdasod7as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where I'd like each of those chunks (that start with MSH| and go to the location of the next MSH|) read into a single (large text) variable, and where each of the chunks would be it's own record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So basically, read through a text file, when encountering MSH|, dump everything (including the MSH|) into a single variable, then when it runs into the next MSH|, end that first record and start the second record with MSH|, etc. all the way to the end of the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone shine light on how to accomplish this? Thank you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you have any idea how long that resulting text variable would have to be, as in character count?&lt;/P&gt;
&lt;P&gt;Does your source file actually contain linefeeds and/or carriage returns (end of lines?). Do you want those linefeed or carriage return characters as part of the "chunk"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would help to post an actual sample of the file, or something with the same sort of structure and content. Post into a code box opened with the forum's {I} icon as the main message windows will reformat text.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 17:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522290#M141771</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-12-18T17:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: Importing large file, single variable to contain all info in record, new record at each "MS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522298#M141773</link>
      <description>&lt;P&gt;Hi Ballardw,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If possible, I'd like the length of that all-encompassing string variable to be 32,767 just to account for longer "chunks". They will not get that long, but will vary in length.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The actual data contains line breaks between MSH chunks, but it doesn't matter whether they are retained or not in what is saved to the SAS dataset. Ideally, the solution would not rely on those line breaks, and instead rely on the MSH| characters, as I don't know whether the format of the original large file might change and there not be line breaks between them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll try to make a better illustration of what the source file looks like, note please that the &amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt; are not actual strings within the file, but when I view a source file in NotePad++ and ask to show all symbols, the &amp;lt;CR&amp;gt; and &amp;lt;LF&amp;gt; symbols appear at the end of each line and at the front of the blank lines. I definitely need to keep whatever symbols/characters are present within the MSH "chunk"&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;MSH|asdklajsd&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
OBX|asdkjasd1923&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
ORC|12391283&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
NTE|1239182390&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
MSH|fs8dfiashdfk&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
ORC|as8da7s9d8ah&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
MSH|scfsdf0as9d8f&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;
OBX|as0d89asdasdjk&amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, what I'm trying to do here is this:&lt;/P&gt;
&lt;P&gt;Take this giant text file and create individual files containing each MSH "chunk". I have some macro code already where I can loop through the SAS table and generate a new file for each record, I just don't know how to generate the SAS dataset containing the file contents.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 18:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522298#M141773</guid>
      <dc:creator>ucdcrush</dc:creator>
      <dc:date>2018-12-18T18:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Importing large file, single variable to contain all info in record, new record at each "MS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522322#M141779</link>
      <description>&lt;P&gt;Here's one approach ...&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;data want;
infile text end=done;
length longvar $32767;
retain longvar;
input @;
if _infile_ =: 'MSH': then do;
   if _n_ &amp;gt; 1 then output;
   longvar = _infile_;
end;
else longvar = catx('|', longvar, _infile_);
if done then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I inserted pipes between original text records.&amp;nbsp; So you won't get:&amp;nbsp; MSH|abc|OBX|abd&lt;/P&gt;
&lt;P&gt;Instead, you will get:&amp;nbsp; MSH|abc|OBX|abd&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's an issue, you can always change the line that does this to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else longvar = cats(longvar, _infile_);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested code at this point, so might need a small amount of tweaking.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 19:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522322#M141779</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-12-18T19:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Importing large file, single variable to contain all info in record, new record at each "MS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522332#M141785</link>
      <description>&lt;P&gt;Hi Astounding, thank you, I think it's close!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems that the resulting longvar is a single line, and that the line breaks within the "chunk" are gone. When I paste the resulting string into a text file, it's on a single line and the next system in line doesn't apparently work without those line breaks that were present in the original file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to include those characters (or perhaps include a delineator in their place) within the input step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 20:34:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522332#M141785</guid>
      <dc:creator>ucdcrush</dc:creator>
      <dc:date>2018-12-18T20:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Importing large file, single variable to contain all info in record, new record at each "MS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522338#M141788</link>
      <description>&lt;P&gt;I'm now experimenting where I just bring in each line as a new record, into the some Longvar variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can I loop through that resulting SAS table and assign a "chunk number", as in below?&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;PRE&gt;&lt;CODE class=" language-sas"&gt;LONGVAR                             CHUNKNUM

MSH asdas lkajsd                         1
OBX askldjaslkdjas ldk                   1  
                                         1 
MSH asas342sd                            2
OBC ask1234k4sldkj                       2  
                                         2
MSH asaas8df79sd7f                       3
OBR asd89a7s9das                         3 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 20:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522338#M141788</guid>
      <dc:creator>ucdcrush</dc:creator>
      <dc:date>2018-12-18T20:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Importing large file, single variable to contain all info in record, new record at each "MS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522341#M141789</link>
      <description>&lt;P&gt;I added a "|" as a delimiter ... you can easily change that to something else, such as "?":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else longvar = catx('?', longvar, _infile_);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But your latest idea is reasonably easy, won't run into length problems, along these lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;infile textfile;&lt;/P&gt;
&lt;P&gt;length longvar $100;&lt;/P&gt;
&lt;P&gt;input&amp;nbsp;@;&lt;/P&gt;
&lt;P&gt;longvar = _infile_;&lt;/P&gt;
&lt;P&gt;if longvar =: 'MSH|' then chunknum + 1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 21:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522341#M141789</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-12-18T21:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: Importing large file, single variable to contain all info in record, new record at each "MS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522344#M141791</link>
      <description>&lt;P&gt;Thanks for your help Astounding! I ended up doing the "chunking" part after I'd read the data in without that chunk variable. It's working now!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 21:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-large-file-single-variable-to-contain-all-info-in/m-p/522344#M141791</guid>
      <dc:creator>ucdcrush</dc:creator>
      <dc:date>2018-12-18T21:39:40Z</dc:date>
    </item>
  </channel>
</rss>

