I need to convert a SAS dataset into text file. After converting into flat file, I am getting ^M
in one of the field (only single row). We are reading this file in python, and python treats it as a new line.
How this junk value can be handled at dataset level before converting into text file ?
In Dataset it simply looks like missing value.
In VI editor value look like this -
}0}0}^M}
What is ^M? Do you mean the two byte string '^M'? Or perhaps the single character '0D'x (also know as a carriage return)?
Either way remove the values from the field in your dataset before writing the values to the text file.
Either change it to some other character.
var1 = translate(var1,' ','0d'x);
Or remove it.
var1 = compress(var1,'0d'x);
If something else is going on you need to provide more information. For example the lines from the SAS log of the step that created the text file.
Hi,
you might have leading not printable characters in your dataset but it's not clear to me.
Can you provide some raw data?
- Cheers -
What is ^M? Do you mean the two byte string '^M'? Or perhaps the single character '0D'x (also know as a carriage return)?
Either way remove the values from the field in your dataset before writing the values to the text file.
Either change it to some other character.
var1 = translate(var1,' ','0d'x);
Or remove it.
var1 = compress(var1,'0d'x);
If something else is going on you need to provide more information. For example the lines from the SAS log of the step that created the text file.
This looks like you crated a file wirth DOS line terminators (cariage return+linefeed) and looking at it in a Unix/Linux environment. Linux and UNIX consider the linefeed as the terminator, regarding and showing the carriage return (Ctrl-M) as part of your data.
We do not now how you create the file but possibly a filename statement is involved. In that case you can use the TERMSTR option to influence the choice of line terminator.
So determining on your situation the ^M may be a problem or not. Depending on what your plan is with the file if may be ok or it needs to go. SAS leaves it to you.
Hope this helps,
- Jan./
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.