<?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 text file with two delimiters using proc import statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-text-file-with-two-delimiters-using-proc-import/m-p/949593#M371428</link>
    <description>&lt;P&gt;Hi! I am trying to import a huge dataset with 55M records and 150 variables into SAS. I used proc import statement to import from notepad to SAS. I had no issues with the process, haven't got any errors but I noticed that data is not getting loaded into the cells. when I tried to see the cause, I ve noticed that there is address variable in the data file with the format :&amp;nbsp;Address1|Address2|City|ZIP that is causing the truncation of the data.&lt;/P&gt;&lt;P&gt;I have used double pipe as the delimiter to import the file into SAS but unfortunately SAS interprets the single pipe(“|”) within the data fields, especially in the address column, as a delimiter, which results in truncation of some information during the import process.&lt;/P&gt;&lt;P&gt;Could someone help me how to deal with this issue? Thanks in Advance!&lt;/P&gt;</description>
    <pubDate>Thu, 31 Oct 2024 14:50:36 GMT</pubDate>
    <dc:creator>DivyaGadde</dc:creator>
    <dc:date>2024-10-31T14:50:36Z</dc:date>
    <item>
      <title>Importing text file with two delimiters using proc import statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-text-file-with-two-delimiters-using-proc-import/m-p/949593#M371428</link>
      <description>&lt;P&gt;Hi! I am trying to import a huge dataset with 55M records and 150 variables into SAS. I used proc import statement to import from notepad to SAS. I had no issues with the process, haven't got any errors but I noticed that data is not getting loaded into the cells. when I tried to see the cause, I ve noticed that there is address variable in the data file with the format :&amp;nbsp;Address1|Address2|City|ZIP that is causing the truncation of the data.&lt;/P&gt;&lt;P&gt;I have used double pipe as the delimiter to import the file into SAS but unfortunately SAS interprets the single pipe(“|”) within the data fields, especially in the address column, as a delimiter, which results in truncation of some information during the import process.&lt;/P&gt;&lt;P&gt;Could someone help me how to deal with this issue? Thanks in Advance!&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2024 14:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-text-file-with-two-delimiters-using-proc-import/m-p/949593#M371428</guid>
      <dc:creator>DivyaGadde</dc:creator>
      <dc:date>2024-10-31T14:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: Importing text file with two delimiters using proc import statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-text-file-with-two-delimiters-using-proc-import/m-p/949594#M371429</link>
      <description>&lt;P&gt;SAS can't handle delimeters OOTB with more than one character.&lt;/P&gt;
&lt;P&gt;If you can recreate the file using quotation around your char variables, and a single char as a delimter, it would hopefully work.&lt;/P&gt;
&lt;P&gt;Your other option is to write your own program to deal with this record layout, using a data step.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2024 14:58:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-text-file-with-two-delimiters-using-proc-import/m-p/949594#M371429</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2024-10-31T14:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: Importing text file with two delimiters using proc import statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-text-file-with-two-delimiters-using-proc-import/m-p/949595#M371430</link>
      <description>&lt;P&gt;Just for clarification: Your file is using a two-character delimiter, ||, between variables and you have one variable that has | characters in the middle?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A data step can use the DLMSTR option to use the || between variables. You would likely want to parse the address information with SCAN after reading it into a single variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data truncation with Proc Import can be the result of not setting a large enough value for the GUESSINGROWS option. By default the procedure only examines a very small number of rows to &lt;STRONG&gt;guess&lt;/STRONG&gt; how long variables may be. A larger setting of Guessingrows can tell the procedure to examine up to 32K rows before setting the length of the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have a document that describes the layout of the file? That may be a great help to write a data step to read the file.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2024 15:26:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-text-file-with-two-delimiters-using-proc-import/m-p/949595#M371430</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-10-31T15:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Importing text file with two delimiters using proc import statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-text-file-with-two-delimiters-using-proc-import/m-p/949597#M371431</link>
      <description>&lt;P&gt;Clarify what you mean by "import".&amp;nbsp; Did you attempt to use PROC IMPORT to &lt;STRONG&gt;read&lt;/STRONG&gt; the file?&lt;/P&gt;
&lt;P&gt;Or did you instead just write a dats step to &lt;STRONG&gt;read&lt;/STRONG&gt; the file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will have much more success writing your own data step.&amp;nbsp; You can set the variable names, types and storage lengths directly instead of forcing SAS to make guesses about what you want them to be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And in your case you could DLMSTR= option on the INFILE statement instead of the DLM= option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DLM= option accepts a string of character where every character is a possible delimiter.&amp;nbsp; So specifying DLM='||' is the same thing as specifying DLM='|'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DLMSTR= option accepts a string that must match exactly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if the address field you mentioned always has 3 internal | characters on every observation then you could read the file using just | as the delimiter, only read the "address" field as four separate fields instead.&amp;nbsp; But if some of the observations have less than 3 | characters in that field then you cannot do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Writing a data step to read a delimited file is simple in SAS.&amp;nbsp; Just define the variables. Attach any needed informats or formats or labels.&amp;nbsp; Then using and INFILE statement and an INPUT statement.&amp;nbsp; If you define the variables in the order they appear in the text file then the INPUT statement can just use a simple positional variable list.&amp;nbsp; If you don't know what names to use for the variables just copy the header line from the file and convert the header text into variable names.&amp;nbsp; You can do a much better job of creating usable names from the header text than PROC IMPORT's guesses will be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your program will look something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile 'myfile.txt' dsd dlmstr='||' firstobs=2 truncover ;
  length id $20 name $50 date 8 age 8 address_list $500 other 8;
  informat date date.;
  format date date9.;
  input id -- other;
  length address1 address2 $200 city $40 zip $10 ;
  address1=scan(address_list,1,'|','m');
  address2=scan(address_list,2,'|','m');
  city=scan(address_list,3,'|','m');
  zip=scan(address_list,4,'|','m');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any value that has embedded delimiter stings (|| in this example) will need to be quoted.&amp;nbsp; So if the address list only had CITY and ZIP so that it was coded as&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;||My City|12345&lt;/PRE&gt;
&lt;P&gt;In the text file it should look like:&lt;/P&gt;
&lt;PRE&gt;previous field||"||My City|12345"||next field&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Oct 2024 15:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-text-file-with-two-delimiters-using-proc-import/m-p/949597#M371431</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-31T15:56:18Z</dc:date>
    </item>
  </channel>
</rss>

