Hi,
I create a report using tagsets.rtf_sample in SAS 9.4 M2 on Windows. For easier formatting of the headers in Word, I later would like to strip the section breaks from the RTF file. To do this, I found some macros here. The macros seem to work OK, but they add unwanted spaces to my RTF, which appear before the first letters of a paragraph. I suspect it has something to do with the way the rtf is read and/or written.
In the code below I create an RTF file, read it and write it out without replacing anything - and the spaces magically appear...! (see screenshot).
How can I get rid of the spaces? Any help is greatly appreciated.
Thanks
Jonas
goptions device=actximg;
options nodate nonumber papersize=A4;
options nocenter;
%let file="c:\test.rtf";
%let dest="c:\test_replaced.rtf";
ods tagsets.rtf_sample
file=&file.
startpage=no
;
ods text='First Page';
ods text='Cars';
proc print data=sashelp.cars noobs;
where Make='Infiniti';
var make model;
run;
ods text='Class';
proc print data=sashelp.class noobs;
where name='Alfred';
run;
ods tagsets.rtf_sample startpage=now;
ods text='Second page';
ods text='Cars';
proc print data=sashelp.cars noobs;
where Make='Infiniti';
var make model;
run;
ods text='Class';
proc print data=sashelp.class noobs;
where name='Alfred';
run;
ods tagsets.rtf_sample close;
%macro TestPut(source=, destination=);
data temp;
length line $1000;
infile &source. length=lg lrecl=1000 end=eof;
input @1 line $varying1000. lg;
run;
data _null_;
set temp;
file &destination. ls=1000;
put line;
run;
%mend TestPut;
%testput(source=&file., destination=&dest.);
EDIT: Oh dear, I realize that @data_null__ was faster.
EDIT 2: Lesson learned: Post a short answer quickly, add details later.
----------
Original reply:
Hi Jonas,
I suggest the following solution: Replace the line
put line;
in macro TestPut by the two lines
lg=lengthn(line);
put line $varying1000. lg;
Rationale: "put line;" performs what is called simple list output. In contrast, "put line $varying1000. lg;" performs formatted output, in this case using the $VARYING1000. format, which corresponds to the $VARYING1000. informat, which was used to read the source file. There are at least two differences between these two output styles:
Try using the $VARYING to write LINE. Note the use of LENGTHN
lg = lengthn(line);
put line $varying1000. lg;
EDIT: Oh dear, I realize that @data_null__ was faster.
EDIT 2: Lesson learned: Post a short answer quickly, add details later.
----------
Original reply:
Hi Jonas,
I suggest the following solution: Replace the line
put line;
in macro TestPut by the two lines
lg=lengthn(line);
put line $varying1000. lg;
Rationale: "put line;" performs what is called simple list output. In contrast, "put line $varying1000. lg;" performs formatted output, in this case using the $VARYING1000. format, which corresponds to the $VARYING1000. informat, which was used to read the source file. There are at least two differences between these two output styles:
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: