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
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.
Please provide some more information, how do you generate your file (share the program)?
Does your source data have in empty record?
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
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?
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;
I am getting same output
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.
Verry verry Thanks Tom this is working fine
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.