<?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: double bytes problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316505#M69176</link>
    <description>&lt;P&gt;What happens if byte&amp;nbsp;61 falls in the middle of a multi-byte character?&lt;/P&gt;</description>
    <pubDate>Sat, 03 Dec 2016 18:08:07 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2016-12-03T18:08:07Z</dc:date>
    <item>
      <title>dobytes problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316477#M69163</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to extract a dataset to a file. Inside a dataset, the&amp;nbsp;first column contains double bytes. The goal is to extract the first column with fixed length of 60 and second column with fixed length of 10.&lt;/P&gt;&lt;P&gt;The problem is that after the extraction, the first field in the first and second row cannot be aligned to the length of 60.&amp;nbsp;Only the rest of rows&amp;nbsp;with pure English can&amp;nbsp;achieve this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Sample code:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data booking;&lt;BR /&gt;input x :$60. y $ :10.;&lt;BR /&gt;datalines;&lt;BR /&gt;ルアドhello checked&lt;BR /&gt;ルアドレス uncheck&lt;BR /&gt;Anderson checked&lt;BR /&gt;EmmaWatson checked&lt;BR /&gt;BradJames checked&lt;BR /&gt;proc print;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set booking;&lt;BR /&gt;file '/plane_booking.txt'&lt;/P&gt;&lt;P&gt;put&lt;BR /&gt;@1 x $60.&lt;BR /&gt;@61 y $10.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Result of the file:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;ルアドhello &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; checked&lt;BR /&gt;ルアドレス &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;uncheck&lt;BR /&gt;Anderson &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; checked&lt;BR /&gt;EmmaWatson &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;checked&lt;BR /&gt;BradJames &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;checked&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Ideal result:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;ルアドhello &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; checked&amp;nbsp;&lt;BR /&gt;ルアドレス &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;uncheck&amp;nbsp;&lt;BR /&gt;Anderson &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; checked&amp;nbsp;&lt;BR /&gt;EmmaWatson &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;checked&amp;nbsp;&lt;BR /&gt;BradJames &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;checked&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly give advice , thank you very much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Dec 2016 14:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316477#M69163</guid>
      <dc:creator>Olime</dc:creator>
      <dc:date>2016-12-04T14:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: double bytes problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316484#M69165</link>
      <description>&lt;P&gt;How about this one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 
data booking;
input x :$60. y $ :10.;
datalines;
梵蒂冈hello checked
苏丹复苏  uncheck
Anderson checked
EmmaWatson checked
BradJames checked
proc print;
run;
 
data _null_;
set booking;
file 'c:\temp\plane_booking.txt';
len=80;
want=x||y;
put want $varying80. len;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Dec 2016 12:32:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316484#M69165</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-03T12:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: double bytes problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316493#M69169</link>
      <description>&lt;P&gt;Hi Ksharp, thanks for the reply but the result is the same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2016 15:23:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316493#M69169</guid>
      <dc:creator>Olime</dc:creator>
      <dc:date>2016-12-03T15:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: double bytes problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316500#M69173</link>
      <description>&lt;P&gt;Are you asking to create a text file with Unicode characters that can take between 1 to 4 bytes each and still be able to read the second column starting at byte number 61?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not just create a delimited file instead? Then you do not need to worry about how many bytes or even how many characters are in each field.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2016 17:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316500#M69173</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-12-03T17:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: double bytes problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316504#M69175</link>
      <description>&lt;P&gt;Hi Tom, yes ,&amp;nbsp;this is the requirement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2016 17:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316504#M69175</guid>
      <dc:creator>Olime</dc:creator>
      <dc:date>2016-12-03T17:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: double bytes problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316505#M69176</link>
      <description>&lt;P&gt;What happens if byte&amp;nbsp;61 falls in the middle of a multi-byte character?&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2016 18:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316505#M69176</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-12-03T18:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: double bytes problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316507#M69178</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;Truncated .&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2016 18:21:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316507#M69178</guid>
      <dc:creator>Olime</dc:creator>
      <dc:date>2016-12-03T18:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: double bytes problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316510#M69180</link>
      <description>&lt;P&gt;Is SAS putting in too many spaces or not enough?&lt;/P&gt;
&lt;P&gt;Either way you should be able to adjust using the difference between the number of characters and the number of bytes in the string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  length string $200 ;
  infile cards truncover ;
  input string ;
  Nbytes = length(string);
  Nchars = klength(string);
  Difference = Nbytes - Nchars ;
cards;
ルアドhello
ルアドレス
Anderson
EmmaWatson
BradJames
;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/6203iDFF82A601BD6FBE6/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.JPG" title="Capture.JPG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's output this as fixed length and see what happens. To make it easier to see I will change the spaces in the string to periods and append carets for the extra padding.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file 'testu8.txt' encoding=utf8;
  length blanks $200 ;
  blanks = repeat('^',199);
  set test ;
  string=ktranslate(string,'.',' ');
  if _n_=1 then put 'NBYTES|NCHARS|DIFF|STRING';
  put nbytes 6. '|' nchars 6. '|' difference 4. '|' @ ;
  put string $15.  blanks $varying15. difference '|' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is what it looks like in Windows WordPad.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/6204i974D35FD773463BC/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;To avoid chopping a character in the middle use KSUBSTR() to limit the number of characters until the number of bytes is less than your output field width.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fix;
 set test;
 do nchars=nchars to 1 by -1 until(nbytes &amp;lt;= 13) ;
   string2 = ksubstr(string,1,nchars);
   nbytes = length(string2);
   put string= string2= nchars= nbytes= ;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2016 19:07:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316510#M69180</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-12-03T19:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: double bytes problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316542#M69199</link>
      <description>&lt;PRE&gt;
That is really weird. I got this.
Check attachment.


&lt;/PRE&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13221i149FE33D01C0BFC4/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="x.png" title="x.png" /&gt;</description>
      <pubDate>Sun, 04 Dec 2016 02:52:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dobytes-problem/m-p/316542#M69199</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-04T02:52:16Z</dc:date>
    </item>
  </channel>
</rss>

