How to eliminate new line character while writing to file in sas

Accepted Solution Solved
Reply
Contributor
Posts: 63
Accepted Solution

How to eliminate new line character while writing to file in sas


Hi,

I want to create a text file from the sas dataset in which i want to write all variables in a record and all records continuously with out going to new line.

Here i'm able to write all recs continuously without going to new line, which is working fine if you see in the sample op file. end of the recs is actually ES02** in sample output file.

But when i see the output file, in between the end of rec (end of rec is mentioned with red mark @ ES02** in the below attached screen shot sample output file) its giving mutiple new lines and which is not at defined interval (i mean it not accuring in perticualr variable/length).

Also I attached the required data format(require output data) for your referance. Can someone please let me know how to resolve this newline character issue.

Thanks in advance.


Accepted Solutions
Solution
‎10-16-2014 01:49 AM
Contributor
Posts: 63

Re: How to eliminate new line character while writing to file in sas

Hi

I got below solution/function to my post in this communities. It was working and can make use of it.

prxchange("s/X/ /",-1,ColName);

View solution in original post


All Replies
Super User
Super User
Posts: 7,682

Re: How to eliminate new line character while writing to file in sas

Hi,

Use the @@ to hold the line pointer:

data have;
  a="djghkjsdhgkjh"; b="kllsdgjlks"; output;
  a="jkhdkjshg"; b="ijgijopg"; output;
run;

data _null_;
  set have;
  file "s:\temp\rob\tt.txt";
  put a b @@;
run;

Contributor
Posts: 63

Re: How to eliminate new line character while writing to file in sas

Hi,

I was using @@ but still there were new line charcters were introduced. So i got the solution and it is working fine now.

prxchange("s/X/ /",-1,ColName);

Respected Advisor
Posts: 3,786

Re: How to eliminate new line character while writing to file in sas

Show your program and the log messages generated from the data step that writes the file. 

Solution
‎10-16-2014 01:49 AM
Contributor
Posts: 63

Re: How to eliminate new line character while writing to file in sas

Hi

I got below solution/function to my post in this communities. It was working and can make use of it.

prxchange("s/X/ /",-1,ColName);

Valued Guide
Posts: 3,208

Re: How to eliminate new line character while writing to file in sas

That is a bad programming approach.

Use the options in a language that are intended for that unless there are serious reasons.

The recfm is supporting what should happen at the end of each iteration.

http://support.sas.com/documentation/cdl/en/hostwin/67279/HTML/default/viewer.htm#chfoptfmain.htm

There are other limitations:

-record definituon is not consistent

- char handling is limited to a maximum often 32k.

That is the visible sas buffer

---->-- ja karman --<-----
Super User
Posts: 9,856

Re: How to eliminate new line character while writing to file in sas

As Jaap pointed out .it is a bad programming way. Let SAS do it for you.

data _null_;
file 'c:\temp\x.txt' recfm=n;
set sashelp.class;
put name age sex;
run;

Xia Keshan

Contributor
Posts: 63

Re: How to eliminate new line character while writing to file in sas

Hi,

I tried that option but its not working properly. still there were some new line characters and its not eliminating totally.

Valued Guide
Posts: 3,208

Re: How to eliminate new line character while writing to file in sas

If you read the documentation on records you will see there are several conventions being used for that. You should understand that and choose the appropriate one.

Why it is bad programming?

Well not understanding your data and your tools you are going into a trial/error development approach that can bring you into uncertain swamp area-s.

If you know utf8 (other encodings)  type packed-type (zoned) and binary being stored physically incorrect transforms can harm all your data and processing.   

---->-- ja karman --<-----
Respected Advisor
Posts: 3,786

Re: How to eliminate new line character while writing to file in sas

Show your work.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 341 views
  • 3 likes
  • 5 in conversation