Deleting space from .txt file after end of data set

Reply
Frequent Contributor
Posts: 87

Deleting space from .txt file after end of data set

Data test;

input name $1-1 age 3-5 sex $ 6-7;

cards;

a   m

b 14 m

c 15 m

d 8  f

e    f

;

run;

data newtest;

file "path";

if missing(age) then do;

want = catt(name,'|',age,'  |',sex);

put @1 want;

else do;

want=catt('|',name,age,sex);

put want;

end;

run;

in text file after last row cursor is moving to next line(one blank space)

wright now iam placing cursor at last obs and using delete key

is there any way that with out using delete key stop cursor at last obs when i use forward

arrow button it must not go to next line

can any one help

Frequent Contributor
Posts: 95

Re: Deleting row space from text

I don't see where a missing value replaced with a space in the code.

Can you post some data and show your wanted output?

I tested above code with sashelp.class data set.

filename t "d:\temp\temp.txt";

data xy;

file t;

set sashelp.class;

if _n_ < 4 then age = .;

if missing(age) then do;

want=catt(NAME,'|',AGE,'|',SEX); /* Got rid of '|' after SEX. Why not use "want=catx('|',NAME,AGE,SEX);" here as well instead of catt() function? */

put @1 want;end;

else do;

want=catx('|',NAME,AGE,SEX);

put want;

end;

run;

Content of Temp.txt:

Alfred|.|M

Alice|.|F

Barbara|.|F

Carol|14|F

Henry|14|M

James|12|M

Jane|12|F

Janet|15|F

Jeffrey|13|M

John|12|M

Joyce|11|F

Judy|14|F

Louise|12|F

Mary|15|F

Philip|16|M

Robert|12|M

Ronald|15|M

Thomas|11|M

William|15|M

Frequent Contributor
Posts: 87

Re: Deleting row space from text

Hello sir,

while generating .txt format  after

william|15|M getting a empty blank row

i want to end in same line i dont want blank space after

data ended

eg :

i am gettign in .txt

William|15|M

(empty row here)

i want no space after M

William|15|M


Frequent Contributor
Posts: 95

Re: Deleting row space from text

Can you explain why you need to remove the blank line after the last row? Thanks.

Frequent Contributor
Posts: 87

Re: Deleting row space from text

This text is entering in to a software

if there is space in last row it is throughing error

data must end at last row


Contributor
Posts: 69

Re: Deleting row space from text

You might have already seen it, but you're missing a comma in the CATT function between SEX and the pipe.

This works for me.

Attachment
Frequent Contributor
Posts: 87

Re: Deleting row space from text

Posted in reply to bentleyj1

Hello

Your code is working for columns

at the end of last column no space is taking

but i am getting a last row empty after data is complete

how can we delete this space

Super User
Super User
Posts: 7,059

Re: Deleting row space from text

There is nothing in the example programs that would generate an extra blank line in the output.  You mentioned that you were sending this via email?  I assume that the process of sending it is adding the extra line.

You could suppress the final end-of-line character from the file.

For example:

data _null_;

  file 'myfile';

  set mydata end=eof;

  put a b @;

  if not eof then put ;

run;

Ask a Question
Discussion stats
  • 7 replies
  • 724 views
  • 0 likes
  • 4 in conversation