<?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 a file using the infile command with special characters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/import-a-file-using-the-infile-command-with-special-characters/m-p/921270#M362803</link>
    <description>&lt;P&gt;What encoding are your SAS session running in?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc options option=ENCODING;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And what is the encoding of your file?&lt;/P&gt;
&lt;P&gt;If I copy your input data in my editor and import it using DATALINES, it looks correct (I'm using LATIN9 as encoding).&lt;/P&gt;</description>
    <pubDate>Thu, 21 Mar 2024 10:02:36 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2024-03-21T10:02:36Z</dc:date>
    <item>
      <title>import a file using the infile command with special characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-file-using-the-infile-command-with-special-characters/m-p/921265#M362799</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need to import a .dat file that contains this information:&amp;nbsp;&lt;A href="https://mega.nz/file/IUgkAZbb#MS_tYyUyLbXjnwNuAw4G3rL6mrkjttYl9fH91dYraKc" target="_blank" rel="noopener"&gt;FILE DAT&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;A                    PER: TEST0  1232156000002024-02-072024-02-07
A                    PER: TEST2 12345678000002024-02-072024-02-07
A                    PER: TEST3 XXXXXXXX000002024-02-072024-02-07
A                    PER: N° Fattura 575000002024-02-072024-02-07&lt;/PRE&gt;
&lt;P&gt;and I use this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename test "path/test.dat";

data test;
	length 
        ONE         $40. 
        TWO         $5.
        three       $10.
        four        $10.
;
	infile test ;
	input;
	        ONE    =ksubstr(_infile_,1	,	41	);
	        TWO    =ksubstr(_INFILE_,41	,	5	);
	        three  =ksubstr(_INFILE_,46	,	10	);
	        four   =ksubstr(_INFILE_,56	,	10	);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have a problem on the last line for the character ° because sas truncates the last character in the first column (missing 5, Fattura 575 is correct)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="result.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94832i3041C603500CCF82/image-size/large?v=v2&amp;amp;px=999" role="button" title="result.png" alt="result.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;How can I import the file correctly?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Luca&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 10:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-file-using-the-infile-command-with-special-characters/m-p/921265#M362799</guid>
      <dc:creator>luca87</dc:creator>
      <dc:date>2024-03-21T10:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: import a file using the infile command with special characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-file-using-the-infile-command-with-special-characters/m-p/921270#M362803</link>
      <description>&lt;P&gt;What encoding are your SAS session running in?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc options option=ENCODING;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And what is the encoding of your file?&lt;/P&gt;
&lt;P&gt;If I copy your input data in my editor and import it using DATALINES, it looks correct (I'm using LATIN9 as encoding).&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 10:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-file-using-the-infile-command-with-special-characters/m-p/921270#M362803</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2024-03-21T10:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: import a file using the infile command with special characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-file-using-the-infile-command-with-special-characters/m-p/921273#M362805</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;The .dat file is in UTF-8.&lt;/P&gt;
&lt;P&gt;SAS:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; ENCODING=UTF-8    Specifies the default character-set encoding for the SAS session.
NOTE: PROCEDURE OPTIONS used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;I add file .dat in the first topic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;BR /&gt;Luca&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 10:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-file-using-the-infile-command-with-special-characters/m-p/921273#M362805</guid>
      <dc:creator>luca87</dc:creator>
      <dc:date>2024-03-21T10:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: import a file using the infile command with special characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-file-using-the-infile-command-with-special-characters/m-p/921372#M362852</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/95093"&gt;@luca87&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the truncation is just due to the insufficiently defined length of variable ONE:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/95093"&gt;@luca87&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;data test;
	length 
        ONE         $&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;40&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;. 
        TWO         $5.
        three       $10.
        four        $10.
;
	infile test ;
	input;
	        ONE    =ksubstr(_infile_,1	,	&lt;FONT size="4" color="#339966"&gt;&lt;STRONG&gt;41&lt;/STRONG&gt;&lt;/FONT&gt;	);
	        TWO    =ksubstr(_INFILE_,41	,	5	);
	        three  =ksubstr(_INFILE_,46	,	10	);
	        four   =ksubstr(_INFILE_,56	,	10	);
run;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;With length $41 (no periods needed after length specifications) variable ONE should contain the missing character.&lt;/P&gt;
&lt;P&gt;EDIT: This will also append an additional character to the values of ONE in the first three observations, though, causing an overlap with variable TWO. To avoid this overlap, use 40, not 41, in the third argument of the KSUBSTR function:&lt;/P&gt;
&lt;PRE&gt;ONE=ksubstr(_infile_, 1, &lt;FONT size="4" color="#339966"&gt;&lt;STRONG&gt;40&lt;/STRONG&gt;&lt;/FONT&gt;);&lt;/PRE&gt;
&lt;P&gt;EDIT 2: To be on the safe side in case of more or longer multi-byte characters to be stored in variable ONE, just increase the defined length of the variable further (as this length is measured in&amp;nbsp;&lt;EM&gt;bytes&lt;/EM&gt;), but keep the 40 (i.e., 40 &lt;EM&gt;characters&lt;/EM&gt;) in the KSUBSTR argument.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 19:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-file-using-the-infile-command-with-special-characters/m-p/921372#M362852</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-03-21T19:38:12Z</dc:date>
    </item>
  </channel>
</rss>

