<?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: Create break lines from text file; Importing text files with no delimitators in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-break-lines-from-text-file-Importing-text-files-with-no/m-p/860181#M339838</link>
    <description>Thank you SO much for this. I ended up using the formatted mode input and it worked:&lt;BR /&gt;data want;&lt;BR /&gt;infile 'myfile.txt' truncover;&lt;BR /&gt;input var1 $4. var2 $8. ;&lt;BR /&gt;run;&lt;BR /&gt;I'm still a beginner and I appreciate this because sometimes I get projects where I know there's a simpler solution in SAS but I hit a wall for a variety of reasons. Somehow I never reviewed or had to use infile/input.&lt;BR /&gt;I was able to import nearly 300 variables using this method and it saved me so much time and stress while also feeling very accomplished.&lt;BR /&gt;For anyone following, I also took advice from Ballardw and a spreadsheet to write the informats and it was helpful.</description>
    <pubDate>Wed, 22 Feb 2023 14:34:50 GMT</pubDate>
    <dc:creator>fastandcurious</dc:creator>
    <dc:date>2023-02-22T14:34:50Z</dc:date>
    <item>
      <title>Create break lines from text file; Importing text files with no delimitators</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-break-lines-from-text-file-Importing-text-files-with-no/m-p/860014#M339746</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Shot in the dark but is anyone is familiar with reading in text files that have no delimitators, or know how to specify different delimitators? I'll take any advice. I have to import a file that is in&lt;SPAN&gt;&amp;nbsp; &lt;STRONG&gt;.dat&lt;/STRONG&gt; format. Unfortunately there are &lt;/SPAN&gt;&lt;STRONG&gt;&lt;U&gt;no&lt;/U&gt;&lt;/STRONG&gt;&lt;SPAN&gt; delimitators but I know what the length of each column should be.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently have to use excel text import wizard and manually create "break lines" based off a format key, and I was hoping there was a way to do it in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;The format key provides the length of each variable in order to specify proper line breaks.&lt;/P&gt;&lt;P&gt;For example, if var1 is a length of 4, I want to tell SAS delineate var1 as a length of 4, var2 is a length of 8, etc.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="fastandcurious_2-1677012199321.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80679i9AE2E42DC1A0860B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="fastandcurious_2-1677012199321.png" alt="fastandcurious_2-1677012199321.png" /&gt;&lt;/span&gt;&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="fastandcurious_1-1677011621699.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80678i8057F0B5314332C9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="fastandcurious_1-1677011621699.png" alt="fastandcurious_1-1677011621699.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2023 20:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-break-lines-from-text-file-Importing-text-files-with-no/m-p/860014#M339746</guid>
      <dc:creator>fastandcurious</dc:creator>
      <dc:date>2023-02-21T20:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create break lines from text file; Importing text files with no delimitators</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-break-lines-from-text-file-Importing-text-files-with-no/m-p/860032#M339758</link>
      <description>&lt;P&gt;This is basic SAS programming 101.&amp;nbsp; How to read in data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_036/lestmtsref/n13ejk9swz5vrbn0z34iazfrp0wp.htm" target="_self"&gt;column mode input&lt;/A&gt;, where you list the column number (or range of columns) after each variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile 'myfile.txt' truncover;
  input var1 $ 1-4 var2 $ 5-12 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_036/lestmtsref/p0f9yk6pd4znukn1rlw6hzkg1url.htm" target="_self"&gt;formatted mode input&lt;/A&gt;, where you list the informat to use after each variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile 'myfile.txt' truncover;
  input var1 $4. var2 $8. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Feb 2023 22:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-break-lines-from-text-file-Importing-text-files-with-no/m-p/860032#M339758</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-21T22:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create break lines from text file; Importing text files with no delimitators</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-break-lines-from-text-file-Importing-text-files-with-no/m-p/860041#M339764</link>
      <description>&lt;P&gt;This is such a common activity that given a good description of the data, (should include which variables are actually numeric, dates, times or datetime values and the expected layout of the values, such as dates in yyyy/mm/dd or ddMONyyyy or currency values) that I use a spreadsheet to write Informat and input statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: there is no standard file format for the .DAT extension. For instance, one version of DAT means "digital audio tape" format and was a moderately common sound file once upon a time. I have worked with DAT extension files that are fixed column, delimited and named (every value is shown as variablename=value like name='John' age=23 ), not to mention some in the appearance of reports that require lots of parsing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Caution: do not save that source text file when opened by a spreadsheet, the values may change on you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2023 22:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-break-lines-from-text-file-Importing-text-files-with-no/m-p/860041#M339764</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-21T22:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create break lines from text file; Importing text files with no delimitators</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-break-lines-from-text-file-Importing-text-files-with-no/m-p/860181#M339838</link>
      <description>Thank you SO much for this. I ended up using the formatted mode input and it worked:&lt;BR /&gt;data want;&lt;BR /&gt;infile 'myfile.txt' truncover;&lt;BR /&gt;input var1 $4. var2 $8. ;&lt;BR /&gt;run;&lt;BR /&gt;I'm still a beginner and I appreciate this because sometimes I get projects where I know there's a simpler solution in SAS but I hit a wall for a variety of reasons. Somehow I never reviewed or had to use infile/input.&lt;BR /&gt;I was able to import nearly 300 variables using this method and it saved me so much time and stress while also feeling very accomplished.&lt;BR /&gt;For anyone following, I also took advice from Ballardw and a spreadsheet to write the informats and it was helpful.</description>
      <pubDate>Wed, 22 Feb 2023 14:34:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-break-lines-from-text-file-Importing-text-files-with-no/m-p/860181#M339838</guid>
      <dc:creator>fastandcurious</dc:creator>
      <dc:date>2023-02-22T14:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create break lines from text file; Importing text files with no delimitators</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-break-lines-from-text-file-Importing-text-files-with-no/m-p/860198#M339840</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438276"&gt;@fastandcurious&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you SO much for this. I ended up using the formatted mode input and it worked:&lt;BR /&gt;data want;&lt;BR /&gt;infile 'myfile.txt' truncover;&lt;BR /&gt;input var1 $4. var2 $8. ;&lt;BR /&gt;run;&lt;BR /&gt;I'm still a beginner and I appreciate this because sometimes I get projects where I know there's a simpler solution in SAS but I hit a wall for a variety of reasons. Somehow I never reviewed or had to use infile/input.&lt;BR /&gt;I was able to import nearly 300 variables using this method and it saved me so much time and stress while also feeling very accomplished.&lt;BR /&gt;For anyone following, I also took advice from Ballardw and a spreadsheet to write the informats and it was helpful.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No need using a spreadsheet to point and click your way through manipulating text.&amp;nbsp; SAS data steps are very good at that.&lt;/P&gt;
&lt;P&gt;So if you have metadata like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vars ;
  input name :$32. type :$4. width ;
cards;
var1 num 4
var2 char 8
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use it to write the input statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set vars end=eof;
  if _n_=1 then put 'input ' @;
  length informat $32 ;
  if type='char' then informat=cats('$',width,'.');
  else informat=cats(width,'.');
  put name informat @;
  if eof then put ';' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will print this line into the log&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input var1 4. var2 $8. ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could stop there and just copy and paste the line into your program, just like I copied it here.&amp;nbsp; Or you could automate even more by writing the line into a file instead and then using %INCLUDE to add the line into your program.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  file code;
  set vars end=eof;
  if _n_=1 then put 'input ' @;
  length informat $32 ;
  if type='char' then informat=cats('$',width,'.');
  else informat=cats(width,'.');
  put name informat @;
  if eof then put ';' ;
run;
data want;
  infile 'myfile.txt' truncover;
%include code / source2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can make it more useful by including INFORMAT and FORMAT fields in the metadata and use those to help generate the code to read the actual data.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 15:43:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-break-lines-from-text-file-Importing-text-files-with-no/m-p/860198#M339840</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-22T15:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create break lines from text file; Importing text files with no delimitators</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-break-lines-from-text-file-Importing-text-files-with-no/m-p/860284#M339857</link>
      <description>Thank you so much for this, this is so helpful and informative! I'm going to look into applying this to the dataset over the next week or so. I appreciate your insight &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 22 Feb 2023 19:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-break-lines-from-text-file-Importing-text-files-with-no/m-p/860284#M339857</guid>
      <dc:creator>fastandcurious</dc:creator>
      <dc:date>2023-02-22T19:33:16Z</dc:date>
    </item>
  </channel>
</rss>

