Hello, i have a question regarding proc report to oinsert empty line;
example dataset below
name, ord
jame, 1
kev, 1
ann, 2
liz, 3
if i use below, it will create empty like after every new ord, but i dont want the blank row after ord=3
compute after ord;
line "";
endcomp;
i tried using a conditional stqatement like below, but it jsut get ignore?
compute after ord;
if ord ne 3 then do;
line "";
end;
endcomp;
any idea?
@TK12 wrote:
(...) adding "@R/RTF'\fs8" to text doesnt seem to work
Have you tried using style attributes rather than raw RTF specifications?
Example:
ods rtf file='C:\Temp\test_report.rtf' style=default;
proc report data=have;
column name ord;
define ord / order;
compute after ord / style(lines)={font_size=5pt};
text=' ';
len=(ord ne 3);
line text $varying. len;
endcomp;
run;
ods rtf close;
I have used 5pt to make the height difference more obvious:
Hello @TK12 and welcome to the SAS Support Communities!
LINE statements in COMPUTE blocks are executed after all other statements. This is why your conditional approach fails.
But you can use the $VARYINGw. format with a length variable whose value is assigned conditionally:
data have;
input name $ ord;
cards;
jame 1
kev 1
ann 2
liz 3
;
proc report data=have;
column name ord;
define ord / order;
compute after ord;
text=' ';
len=(ord ne 3);
line text $varying. len;
endcomp;
run;
The assignment statement
len=(ord ne 3);
is just a shorthand for
if ord ne 3 then len=1; else len=0;
With len=0 the space character in temporary variable text is not written, i.e., no blank line occurs.
Thanks that solve the issue, but is there a way to change the text size(to change line height)?
with line, i can do line "@R/RTF'\fs5"; to change how tall the row is. but that doesnt work here
@TK12 wrote:
nvm figured it out; below workscompute after ord;text="";len=(ord ne 3);line "@R/RTF'\fs8" text $varying. len;endcomp;
That will always write a line because you included a string literal in the LINE statement.
You need to write ZERO bytes in the LINE statement for PROC REPORT to not produce a line.
I am not sure what you want to do but if the goal is to either write "@R/RTF'\fs8" or not have a line at all you need to do something like this:
compute after ord;
text="@R/RTF'\fs8";
len=(ord ne 3)*length(text);
line text $varying. len;
endcomp;
So when ORD is 3 then LEN is set to ZERO. Otherwise LEN is set to the length of TEXT.
Perhaps it would be clearer to do it this way.
compute after ord;
if ord eq 3 then text="@R/RTF'\fs8";
else text=" ";
len=lengthN(text);
line text $varying. len;
endcomp;
The newish LENGTHN() function gets the length of string ignoring the ALL of the trailing spaces. So a string with only spaces will have a length of zero instead of the length of one that the older LENGTH() function calculates.
Thanks, what i am trying to do is
1 create blank line after each ord, except the last one.
2. i need change the blank lines to smaller height, to fit the report into one page. (thats the reason i didnt want to extra blank at the end to save space );
For example, below code works to change the line height to font size 8, but adding "@R/RTF'\fs8" to text doesnt seem to work
compute after ord;
if ord ne 3 then do;
line "@R/RTF'\fs8";
end;
endcomp
@TK12 wrote:
(...) adding "@R/RTF'\fs8" to text doesnt seem to work
Have you tried using style attributes rather than raw RTF specifications?
Example:
ods rtf file='C:\Temp\test_report.rtf' style=default;
proc report data=have;
column name ord;
define ord / order;
compute after ord / style(lines)={font_size=5pt};
text=' ';
len=(ord ne 3);
line text $varying. len;
endcomp;
run;
ods rtf close;
I have used 5pt to make the height difference more obvious:
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.