- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Experts,
I'm generating a fix file, using a sintaxis like this
data _null_;
set filexyz;
file '/data/filexyz' TERMSTR=crlf;
put
@1 account z10.
@11 namex $20.
@31 branch z5.
and the result is something like this:
1234 Robert A 56789
1234 Robert B 56788
as you can see there are 35 characters fixed, but when ñ appears in the name, the result of the length of line is 34 characters
1234 Robert Ñ 56788
I appreciate too much your help, if you have any idea to solve it
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To generate a fixed position text file you need to use single byte encoding. Multiple byte encodings like UTF-8 will need to use multiple bytes to store non-ASCII characters, like the enye in your example, which will mess up the column count.
file '/data/filexyz' TERMSTR=crlf encoding=latin1;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To generate a fixed position text file you need to use single byte encoding. Multiple byte encodings like UTF-8 will need to use multiple bytes to store non-ASCII characters, like the enye in your example, which will mess up the column count.
file '/data/filexyz' TERMSTR=crlf encoding=latin1;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The encoding latin1 did not work, I've got the same problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You will need to provide much more details about what you tried and what result you got. Show the code used to create the text file. And the code used to read the text file.
First what encoding is your SAS session using? Check the value of the ENCODING system option. That option is set at the start of the SAS session, so you need to make sure you are using an single byte encoding for the SAS session.
If you are trying to read a text file and you do not want SAS to transcode the characters from the encoding used by the file to encoding used by the SAS session then you will need to use ENCODING=ANY on the INFILE statement. Then if you did need to transcode the strings read from the file you will need to use the KCVT() function.
In general you should not be writing non-ASCII characters into fixed position files. It will just cause havoc. Can you just not allow character like enye in your text strings?
Also try reading the file as BINARY bytes to see what it contains. For example to check the first 500 bytes of the file you could use a data step like this:
data _null_;
infile 'myfile.txt' recfm=f lrecl=100 obs=5;
input;
list;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Example of input and the code you actually use to "fix" would be appropriate.
Also, what is it supposed to be "fixed" to? We can't tell what isn't working without knowing what is attempted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It´s simple, i´m trying to generate all the lines 35 length, and the lines are 34 length when ñ appears as a letter of the name