BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Jose7
Obsidian | Level 7

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 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

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;
Jose7
Obsidian | Level 7
I get the same issue with latin1, It doesn´t solve the problem


Jose7
Obsidian | Level 7

The encoding latin1 did not work, I've got the same problem

Tom
Super User Tom
Super User

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;
ballardw
Super User

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.

 

 

 

 

Jose7
Obsidian | Level 7

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1004 views
  • 0 likes
  • 3 in conversation