BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PRAVIN_JAIN
Calcite | Level 5

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}

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

3 REPLIES 3
Oligolas
Barite | Level 11

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 -

Tom
Super User Tom
Super User

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.

jklaverstijn
Rhodochrosite | Level 12

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 1024 views
  • 0 likes
  • 4 in conversation