Hello,
I would like to add an header like 'the purple line' (line 'This is a LINE before data starts displaying';) after Var1 eq 'D'
Here's my code but it is missing something to obtains what I want.
Does someone know how to add an header after the Nth observations?
Regards,
data Dataset1;
infile datalines delimiter=',';
input var1 $ var2 $ var3 $ var4 $ var5 $;
datalines;
A,1,2,3,4
B,1.1,1.2,1.3,1.4
C,2.1,2.2,2.3,2.4
D,3.1,3.2,3.3,3.4
E,5,6,7,8
F,5.1,5.2,5.3,5.4
G,6.1,6.2,6.3,6.4
H,7.1,7.2,7.3,7.4
;
RUN;
proc report data=Work.dataset1 nowd;
columns (Var1
('Period1' Var2 Var3 )
('Period2' Var4 var5 ));
compute before / style={just=l color=purple};
line 'This is a LINE before data starts displaying';
endcomp;
define Var1 / 'Variable1'
style(column)={just=l};
define Var2 / 'Variable2'
style(column)={just=c};
define Var3 / 'Variable3'
style(column)={just=c};
define Var4 / 'Variable4'
style(column)={just=c};
define Var5 / 'Variable5'
style(column)={just=c};
run;
Hi:
With the use of helper variables you can create a fake "grp" variable that allows you to control where the line is written. Here's some sample code that changes the purple line differently for each program. The key is using the $varying. format with a variable for length set to 0, because the length value of 0 causes PROC REPORT to suppress the LINE. This is a feature of PROC REPORT.
Your other choice would be to use the Report Writing Interface if you don't want to use PROC REPORT.
Hope this helps,
Cynthia
data Dataset1;
infile datalines delimiter=',';
input var1 $ var2 $ var3 $ var4 $ var5 $;
** make a variable called "grp" that can be used;
** in the PROC REPORT step to turn purple LINE on or off;
if var1 in ('A' 'B' ) then grp = 1;
else if var1 in ('C' 'D') then grp = 2;
else if var1 in ('E' 'F') then grp = 3;
else grp = 4;
datalines;
A,1,2,3,4
B,1.1,1.2,1.3,1.4
C,2.1,2.2,2.3,2.4
D,3.1,3.2,3.3,3.4
E,5,6,7,8
F,5.1,5.2,5.3,5.4
G,6.1,6.2,6.3,6.4
H,7.1,7.2,7.3,7.4
;
RUN;
** put purple line above grp values for C and G;
title '1) Put purple line above C and G';
proc report data=Work.dataset1 nowd;
columns grp (Var1
('Period1' Var2 Var3 )
('Period2' Var4 var5 ));
define grp / order noprint;
define Var1 / display 'Variable1'
style(column)={just=l};
define Var2 / display 'Variable2'
style(column)={just=c};
define Var3 / display 'Variable3'
style(column)={just=c};
define Var4 / display 'Variable4'
style(column)={just=c};
define Var5 / display 'Variable5'
style(column)={just=c};
** put the desired line before "groups" 2 and 4;
compute before grp/ style={just=l color=purple};
length brkline $50;
brkline = 'This is a LINE before data starts displaying';
if grp in (2,4) then lg = 50;
else lg = 0;
line brkline $varying. lg;
endcomp;
run;
title '2) Put line above A and E';
proc report data=Work.dataset1 nowd;
columns grp (Var1
('Period1' Var2 Var3 )
('Period2' Var4 var5 ));
define grp / order noprint;
define Var1 / display 'Variable1'
style(column)={just=l};
define Var2 / display 'Variable2'
style(column)={just=c};
define Var3 / display 'Variable3'
style(column)={just=c};
define Var4 / display 'Variable4'
style(column)={just=c};
define Var5 / display 'Variable5'
style(column)={just=c};
** put the desired line before "groups" 1 and 3;
compute before grp/ style={just=l color=purple};
length brkline $50;
brkline = 'This is a LINE before data starts displaying';
if grp in (1,3) then lg = 50;
else lg = 0;
line brkline $varying. lg;
endcomp;
run;
Hi:
With the use of helper variables you can create a fake "grp" variable that allows you to control where the line is written. Here's some sample code that changes the purple line differently for each program. The key is using the $varying. format with a variable for length set to 0, because the length value of 0 causes PROC REPORT to suppress the LINE. This is a feature of PROC REPORT.
Your other choice would be to use the Report Writing Interface if you don't want to use PROC REPORT.
Hope this helps,
Cynthia
data Dataset1;
infile datalines delimiter=',';
input var1 $ var2 $ var3 $ var4 $ var5 $;
** make a variable called "grp" that can be used;
** in the PROC REPORT step to turn purple LINE on or off;
if var1 in ('A' 'B' ) then grp = 1;
else if var1 in ('C' 'D') then grp = 2;
else if var1 in ('E' 'F') then grp = 3;
else grp = 4;
datalines;
A,1,2,3,4
B,1.1,1.2,1.3,1.4
C,2.1,2.2,2.3,2.4
D,3.1,3.2,3.3,3.4
E,5,6,7,8
F,5.1,5.2,5.3,5.4
G,6.1,6.2,6.3,6.4
H,7.1,7.2,7.3,7.4
;
RUN;
** put purple line above grp values for C and G;
title '1) Put purple line above C and G';
proc report data=Work.dataset1 nowd;
columns grp (Var1
('Period1' Var2 Var3 )
('Period2' Var4 var5 ));
define grp / order noprint;
define Var1 / display 'Variable1'
style(column)={just=l};
define Var2 / display 'Variable2'
style(column)={just=c};
define Var3 / display 'Variable3'
style(column)={just=c};
define Var4 / display 'Variable4'
style(column)={just=c};
define Var5 / display 'Variable5'
style(column)={just=c};
** put the desired line before "groups" 2 and 4;
compute before grp/ style={just=l color=purple};
length brkline $50;
brkline = 'This is a LINE before data starts displaying';
if grp in (2,4) then lg = 50;
else lg = 0;
line brkline $varying. lg;
endcomp;
run;
title '2) Put line above A and E';
proc report data=Work.dataset1 nowd;
columns grp (Var1
('Period1' Var2 Var3 )
('Period2' Var4 var5 ));
define grp / order noprint;
define Var1 / display 'Variable1'
style(column)={just=l};
define Var2 / display 'Variable2'
style(column)={just=c};
define Var3 / display 'Variable3'
style(column)={just=c};
define Var4 / display 'Variable4'
style(column)={just=c};
define Var5 / display 'Variable5'
style(column)={just=c};
** put the desired line before "groups" 1 and 3;
compute before grp/ style={just=l color=purple};
length brkline $50;
brkline = 'This is a LINE before data starts displaying';
if grp in (1,3) then lg = 50;
else lg = 0;
line brkline $varying. lg;
endcomp;
run;
Exactly what I was looking for.
Tanks a lot.
What can I do if the second line of text (header..) is different from the first one?
I have found the solution for two line
Hi:
You cannot execute a LINE statement conditionally, but you can change the value of your BRKLINE variable conditionally, something like this:
compute before ????;
if some-condition = xxx then do;
brkline = 'One Thing';
lg = 10;
end;
else if some-condition = yyy then do;
brkline = 'Second Thing';
lg = 15;
end;
line brkline $varying. lg;
endcomp;
Basically, change the value of the line you are going to write based on the condition.
Cynthia
Hello Cynthia,
I have used brealine and brealine2 and it works fine. However, your solution is nicer.
Regarding the possibility to add a background image, is it possible to do it without the use of a proc template?
Also, I know that it is possible to use preimage and postimage with proc report. Is it possible to adjust the size of those images in order to have both, the report and the image on the same page.
Thanks in advance for your help.
Regards,
Alain
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.