Desktop productivity for business analysts and programmers

How to add an header after the nth observations using proc report

Accepted Solution Solved
Reply
Regular Contributor
Posts: 168
Accepted Solution

How to add an header after the nth observations using proc report

Hello,

 

I would like to add an header like 'the purple line' (line 'This is a LINE before data starts displaying'Smiley Wink 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;


Accepted Solutions
Solution
‎04-24-2018 08:06 AM
SAS Super FREQ
Posts: 9,433

Re: How to add an header after the nth observations using proc report

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;

View solution in original post


All Replies
Solution
‎04-24-2018 08:06 AM
SAS Super FREQ
Posts: 9,433

Re: How to add an header after the nth observations using proc report

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;
Regular Contributor
Posts: 168

Re: How to add an header after the nth observations using proc report

Posted in reply to Cynthia_sas

Exactly what I was looking for.

Tanks a lot.

 

 

Regular Contributor
Posts: 168

Re: How to add an header after the nth observations using proc report

Posted in reply to Cynthia_sas

What can I do if the second line of text (header..) is different from the first one?

Regular Contributor
Posts: 168

Re: How to add an header after the nth observations using proc report

I have found the solution for two line

SAS Super FREQ
Posts: 9,433

Re: How to add an header after the nth observations using proc report

[ Edited ]

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

Regular Contributor
Posts: 168

Re: How to add an header after the nth observations using proc report

Posted in reply to Cynthia_sas

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

SAS Super FREQ
Posts: 9,433

Re: How to add an header after the nth observations using proc report

Hi:
There is no sizing with preimage and postimage -- you'll have to be sure the image is sized correctly before you insert it into your output--you did not indicate or I may have missed your destination of interest. With HTML, there really isn't a "page" to worry about, since 1 HTML file could be many physical pages. But with RTF and PDF, there are pages that are controlled by margin options.

There are limitations to which destinations support BACKGROUNDIMAGE, so you'd have to look in the documentation: http://go.documentation.sas.com/?docsetId=odsug&docsetTarget=p0xi2cygmfk0wkn1ei625zq5r488.htm&docset...

You don't necessarily need to put your backgroundimage information in a template if you are using PROC PRINT, PROC REPORT or PROC TABULATE and want the image as the background in a cell or as part of the table, but I believe you do need to use a template if you want the image to be on the whole page (as for a PDF page). That would be a question for Tech Support, so you can show them the code that you've tried and you can describe what destination you want and where you want the image.

Cynthia
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 235 views
  • 1 like
  • 2 in conversation