<?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: Import .txt tab delimited file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-txt-tab-delimited-file/m-p/124504#M25474</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please try the below code, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i used infile statement to import the tab delimited .txt file. also with regard to the data truncation, while importing in the input statement use the name and give the maximum length possible something like name :$20.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename test "~path\test.txt";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile test dlm='09'x missover;&lt;/P&gt;&lt;P&gt;input iD TxtFileVble :$20.;&lt;/P&gt;&lt;P&gt;NewVbleA=substr(TxtFileVble,1,2);&lt;/P&gt;&lt;P&gt;NewVbleB=substr(TxtFileVble,3,7);&lt;/P&gt;&lt;P&gt;NewVbleC=substr(TxtFileVble,8,7);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jagadish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 26 Oct 2013 00:18:15 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2013-10-26T00:18:15Z</dc:date>
    <item>
      <title>Import .txt tab delimited file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-txt-tab-delimited-file/m-p/124502#M25472</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good Afternoon,&lt;/P&gt;&lt;P&gt;I'm importing a .txt file (Tab delimited). &lt;/P&gt;&lt;P&gt;In the .txt file there's a variable that is 14 digits long &amp;amp; some start with zeros.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Original Number in Text File:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ID TxtFileVble&lt;/P&gt;&lt;P&gt;1 01611430000000&lt;/P&gt;&lt;P&gt;2 19734376023758&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once imported into SAS using File, Import Wizard, SAS converts the variable into a 'BEST12.' numeric format and the leading zero drops:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp; ImportedVble&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.61143E12&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.9734376E13&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;I need to do 3 things:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FIRST:&amp;nbsp; I need to convert ImportedVble from the numberic BEST format into a character format with a leading zero only where it was missing so it looks like this:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp; ZeroAddedVble&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01611430000000&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 19734376023758&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SECOND: I need to Parse it out (using Substr?) 3 new variables: &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1st new variable&amp;nbsp; (1st and 2nd digits of 'OldVble'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID&amp;nbsp; NewVbleA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 01&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 19&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 2nd new variable (3rd digit through 7th digit of 'OldVble')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID NewVbleB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 03456&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp; 73437&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 3rd new vble (8th digit through 14th digit of 'OldVble')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID NewVbleC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 0000000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp; 6023758&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What's the most efficient way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried this&amp;nbsp; but it doesn't work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data rename;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set fileA;&lt;/P&gt;&lt;P&gt;format NewVbleA $2. NewVbleB $5. NewVbleC $7.&lt;/P&gt;&lt;P&gt;char_ImportedVble=strip(put(ImportedVble, 13.));&lt;/P&gt;&lt;P&gt;dr0p ImportedVble;&lt;/P&gt;&lt;P&gt;rename char_ImportedVble=ImportedVble;&lt;/P&gt;&lt;P&gt;NewVbleA=substr(ImportedVble, 1, 2)&lt;/P&gt;&lt;P&gt;NewVbleB=substr(ImportedVble, 3,7)&lt;/P&gt;&lt;P&gt;NewVlbeC=substr(ImportedVble, 8,7);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THIRD:&amp;nbsp; In the text file one variable is a name of an institution but when I used proc import, it cutoff all of the variable and only retained the first letter.&lt;/P&gt;&lt;P&gt;How do you make sure SAS doesn't cut the information off?&amp;nbsp; Is it better to just import the .txt file into an Excel file and then import into SAS?&lt;/P&gt;&lt;P&gt;Any help you can give is much appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Oct 2013 23:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-txt-tab-delimited-file/m-p/124502#M25472</guid>
      <dc:creator>jcis7</dc:creator>
      <dc:date>2013-10-25T23:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Import .txt tab delimited file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-txt-tab-delimited-file/m-p/124503#M25473</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can get control by just writing the code to read the file yourself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code to read a tab delimited file is easy to write yourself if you know the variable names. (just grab the first line of the file and paste it into the program editor!).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data want ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; infile 'myfile.txt' dlm='09'x dsd truncover lrecl=1000000;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; length &lt;SPAN style="background-color: #ffffff;"&gt;ID 8&amp;nbsp; TxtFileVble $14 ;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; input id txtfilevble ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are using SAS display manager you can use the IMPORT wizard (or call PROC IMPORT) and then recall the data step that it generated and fix it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have a number and you want to convert it to a text string with leading zero then use the PUT function.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;newvar = put(oldvar,Z14.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are happy to leave it as a number and just want it to LOOK like it has leading zeros then just attach a format to it.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;format oldvar Z14. ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are a number of issues with your data step.&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; You are using a FORMAT statement where you clearly want a LENGTH statement. Format does NOT define the length of a variable, other than in the normal way that SAS will guess what type of variable you want based on how you first reference it.&lt;/P&gt;&lt;P&gt;2) Just use the PUT() statement to generate the string variable. Use Z format to add the leading zeros. You said it was length 14&amp;nbsp; , but use format of only 13.&lt;/P&gt;&lt;P&gt;3) Typo with a zero in place of the letter 0.&lt;/P&gt;&lt;P&gt;4) SUBSTR() syntax is substr(STRING,beginning [,length] ).&lt;/P&gt;&lt;P&gt;5) You need to reference the new variable using the name it has in this data step, the RENAME does not take effect until the record is written out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data rename;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; set fileA;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; length char_ImportedVble $14 NewVbleA $2 NewVbleB $5 NewVbleC $7 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; char_ImportedVble=put(ImportedVble,Z14.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; drop ImportedVble;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; rename char_ImportedVble=ImportedVble;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; NewVbleA=substr(&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;char_&lt;/SPAN&gt;ImportedVble, 1,2)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; NewVbleB=substr(&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;char_&lt;/SPAN&gt;ImportedVble, 3,5)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; NewVlbeC=substr(&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;char_&lt;/SPAN&gt;ImportedVble, 8);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Truncation could be caused by LRECL setting being too short. Or if you used PROC IMPORT then SAS might not have examined all of the file and so set the variable length too short to store the full name.&amp;nbsp; You can try the GUESSINGROWS setting.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Oct 2013 00:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-txt-tab-delimited-file/m-p/124503#M25473</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-10-26T00:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Import .txt tab delimited file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-txt-tab-delimited-file/m-p/124504#M25474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please try the below code, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i used infile statement to import the tab delimited .txt file. also with regard to the data truncation, while importing in the input statement use the name and give the maximum length possible something like name :$20.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename test "~path\test.txt";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile test dlm='09'x missover;&lt;/P&gt;&lt;P&gt;input iD TxtFileVble :$20.;&lt;/P&gt;&lt;P&gt;NewVbleA=substr(TxtFileVble,1,2);&lt;/P&gt;&lt;P&gt;NewVbleB=substr(TxtFileVble,3,7);&lt;/P&gt;&lt;P&gt;NewVbleC=substr(TxtFileVble,8,7);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jagadish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Oct 2013 00:18:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-txt-tab-delimited-file/m-p/124504#M25474</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2013-10-26T00:18:15Z</dc:date>
    </item>
  </channel>
</rss>

