BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

7 REPLIES 7
Cynthia_sas
SAS Super FREQ

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;
alepage
Barite | Level 11

Exactly what I was looking for.

Tanks a lot.

 

 

alepage
Barite | Level 11

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

alepage
Barite | Level 11

I have found the solution for two line

Cynthia_sas
SAS Super FREQ

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

alepage
Barite | Level 11

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

Cynthia_sas
SAS Super FREQ
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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