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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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