Deleting space from output .txt file

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 87
Accepted Solution

Deleting space from output .txt file

I am generating .txt file

i want to fit output text as to data generate

(ie., i dont want to have a space after complte data printed on .txt)

now i am putting pointer on last observation and using delte key after generating .txt

is there any way with out using delete key to eliminate last empty row

here i have attached 2 immages to make my question clear


Output With pointer next line.jpgOutput i want.png

Accepted Solutions
Solution
‎02-01-2013 05:58 PM
Super User
Super User
Posts: 7,039

Re: Deleting space from output .txt file

I still have no idea what program would prefer that the last line of a file NOT end in a proper end of line.  Are you sure you can't just fix the other program that is expecting files in a non-standard format?

You should be able to get what you want by using RECFM=N and explicitly writing the end-of-line characters where you want them.

Try this for example.  If you are running on Unix then put just '0A'x instead of '0D0A'x ;

filename two '/path.txt' ;

data example;

  input name $  no marks;

  file two recfm=n;

  if _n_ > 1 then put '0D0A'x ;

  put name $7. ' |'  no 2. '|' marks 3. ;

datalines;

a 1 30

b 2 20

c 3 .

;

run;

data _null_;

  infile two recfm=f lrecl=200 ;

  input;

  list;

run;

RULE:     ----+----1----+----2----+----3----+----4----+----5----+

1   CHAR  a       | 1| 30..b       | 2| 20..c       | 3|  . 49

    ZONE  6222222272372330062222222723723300622222227237222

    NUMR  10000000C01C030DA20000000C02C020DA30000000C03C00E

NOTE: 1 record was read from the infile TWO.

data _null_;

  infile two;

  input;

  list;

run;


RULE:     ----+----1----+----2----+----3----+----4----+----5----+

1         a       | 1| 30 15

2         b       | 2| 20 15

3         c       | 3|  . 15

NOTE: 3 records were read from the infile TWO.

View solution in original post


All Replies
Super User
Posts: 5,424

Re: Deleting space from output .txt file

Please provide some more information, how do you generate your file (share the program)?

Does your source data have in empty record?

Data never sleeps
Frequent Contributor
Posts: 87

Re: Deleting space from output .txt file

data example;

input name $  no marks ;

datalines;

a 1 30

b 2 20

c 3  

d 4 15

e 5  20

;

run;

data new;

file "/path.txt";
set example;

put name $7. ' |'  no $2. '|' marks $3,;

run;

after last observation in marks ie 20 the pointer is moving to next line

i want output text pointer end at last observation ie 20

Super User
Posts: 5,424

Re: Deleting space from output .txt file

Apart from  that your example code is not working, I don't get any extra blank row in my files.

I'm in Windows (and you in UNIX?), but I don't that will make any difference.

Why don't you post a working program with a log?

Data never sleeps
Super User
Super User
Posts: 7,039

Re: Deleting space from output .txt file

Sounds like your real problem is with whatever program you are using the read the generated file.  You should see if you can adjust that program to accept files in a normal format.

If you want to generate a file where the last line of data does not contain an end of line marker then you need to manage when SAS puts the end of line.  Using the trailing @ on the put statement will prevent SAS from automatically generating the end of line.

data _null_;

  file "/path.txt";
  set example end=eof ;

  put name $7. ' |'  no $2. '|' marks $3. @;

  if not eof then put ;

run;

Frequent Contributor
Posts: 87

Re: Deleting space from output .txt file

I am getting same output

Solution
‎02-01-2013 05:58 PM
Super User
Super User
Posts: 7,039

Re: Deleting space from output .txt file

I still have no idea what program would prefer that the last line of a file NOT end in a proper end of line.  Are you sure you can't just fix the other program that is expecting files in a non-standard format?

You should be able to get what you want by using RECFM=N and explicitly writing the end-of-line characters where you want them.

Try this for example.  If you are running on Unix then put just '0A'x instead of '0D0A'x ;

filename two '/path.txt' ;

data example;

  input name $  no marks;

  file two recfm=n;

  if _n_ > 1 then put '0D0A'x ;

  put name $7. ' |'  no 2. '|' marks 3. ;

datalines;

a 1 30

b 2 20

c 3 .

;

run;

data _null_;

  infile two recfm=f lrecl=200 ;

  input;

  list;

run;

RULE:     ----+----1----+----2----+----3----+----4----+----5----+

1   CHAR  a       | 1| 30..b       | 2| 20..c       | 3|  . 49

    ZONE  6222222272372330062222222723723300622222227237222

    NUMR  10000000C01C030DA20000000C02C020DA30000000C03C00E

NOTE: 1 record was read from the infile TWO.

data _null_;

  infile two;

  input;

  list;

run;


RULE:     ----+----1----+----2----+----3----+----4----+----5----+

1         a       | 1| 30 15

2         b       | 2| 20 15

3         c       | 3|  . 15

NOTE: 3 records were read from the infile TWO.

Frequent Contributor
Posts: 87

Re: Deleting space from output .txt file

Verry verry Thanks Tom this is working fine

🔒 This topic is solved and locked.

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

Discussion stats
  • 7 replies
  • 325 views
  • 2 likes
  • 3 in conversation