11-30-2016 11:09 PM
I would like to export a sas data to a text file. It is a fixed length file and I handle it in this way
set data end=last;
FILE "output.txt" ;
*** Details ***;
While this work only without any special characters in the data, once the variable contains any special character, it will automatically truncate the length of the row. (e.g. with 1 utf8 coding character in Field3, it will occupy 3bytes length and which result the final length trim to 8 instead of 10)
Please advice how can I handle it. Many thanks.
12-01-2016 01:37 AM - edited 12-01-2016 01:45 AM
Add ENCODING= option on FILE statement.
Available values you shall find in:
FILE "output.txt" encoding = "ANSI";
The encoding valur should fit the target platform of your output;
12-01-2016 02:44 AM
Thanks for your reply.
I have added
but it gives the same result which still truncate the variable length in output text files...
12-01-2016 03:07 AM
If a character encoded 2 bytes you can't hold it in one byte.
What is the target of the file ? is it WINDOWS / LINUX / MF ?
What language is the text ?
If just latin alphanumeric and special character like dot, comma, etc. -
then use encoding = ansi (one byte per character);
12-01-2016 03:25 AM
Yes, we have to use UTF8 as it contains Chinese Characters.
While I have to transfer the file to system so the length can't be changed.
Attached is a reference file which you can see even Chinese characters / numbers, each characters occpy the same length (using notepad+++ to check).
However, once the output generated from SAS, the length will be truncated.
12-01-2016 03:42 AM
Are the special characters in a text significant ?
Can you omit them or replace them by space ? (using COMPRESS or TRANSLATE functions)
Otherwise - maybe the fix length should consider two bytes character as valid ?
Show examples to your system team and consult with them.
12-01-2016 04:07 AM
Try local format. Or $varying. data have; input x : $40. y : $10.; cards; 一二山石 打碎 1234 er ; run; data _null_; set have; file '/folders/myfolders/want.txt'; PUT @1 x $kanji40. @41 y $kanji10. ; run;