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

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
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

7 REPLIES 7
LinusH
Tourmaline | Level 20

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
santhosh
Fluorite | Level 6

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

LinusH
Tourmaline | Level 20

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
Tom
Super User Tom
Super User

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;

santhosh
Fluorite | Level 6

I am getting same output

Tom
Super User Tom
Super User

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.

santhosh
Fluorite | Level 6

Verry verry Thanks Tom this is working fine

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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