The SAS Output Delivery System and reporting techniques

Different Background Colour in each printed line?

Accepted Solution Solved
Reply
Contributor alr
Contributor
Posts: 39
Accepted Solution

Different Background Colour in each printed line?

Hi
I have this simple proc print:

proc print data=sashelp.class noobs label;
   var    name / style={just=left};
   var    Sex / style={BACKGROUND=white OUTPUTWIDTH=40};
   var    Age / style={BACKGROUND=white OUTPUTWIDTH=40};
   var    Height / style={BACKGROUND=red OUTPUTWIDTH=40};
   var    Weight / style={BACKGROUND=white OUTPUTWIDTH=40};
run;

Is it possible to change the Background Colour in “age” based on the values in “name” using some pre-generated formats?

For example all the students named Alfred have their own format and all students named Alice have another format? (simply a different format for each line)

Is it possible in proc report?


Accepted Solutions
Solution
‎04-10-2014 03:24 PM
SAS Super FREQ
Posts: 8,719

Re: Different Background Colour in each printed line?

Hi:

  For some information about PROC REPORT and styles, this paper shows some of the style changes (https://support.sas.com/resources/papers/proceedings13/366-2013.pdf). For information about how PROC REPORT works, you might want to refer to the PROC REPORT  documentation. Changing Age based on name is an example in the above paper shown on page 13.

cynthia

View solution in original post


All Replies
Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: Different Background Colour in each printed line?

Hi,

Yes, you need a compute section and a call style command in proc report.  Here are some examples:

http://support.sas.com/resources/papers/stylesinprocs.pdf

Contributor alr
Contributor
Posts: 39

Re: Different Background Colour in each printed line?

Thank you.

Is it possible to compute a group of variables?

Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: Different Background Colour in each printed line?

Could you clarify the request.  You can use the group option in the define for columns. And set styles for row/col.  It may just be easier if you want something else to have a nonprinted variable to indicate a 'group' and use that to change the style of the element, though perhaps an example of what you require may clarify.

Contributor alr
Contributor
Posts: 39

Re: Different Background Colour in each printed line?

I have a list of KPI’s and each line should be formatted separately.

KPIID – KPI1 – KPI2 – KPI3 – KPI4 – KPI5

Then the code is:

compute kpi1;
if kpiid = 1 then
call define ('kpi1','style','style=[background=stndr.]');
endcomp;
compute kpi2;
if kpiid = 1 then
call define ('kpi2','style','style=[background=stndr.]');
endcomp;
and so on for kpi3, kpi4 and kpi5.

KPI1 to KPI5 have same background format for each KPIID.

I just thought if it is possible to reduce the code and somehow write one compute for KPI1 to KPI5 and set the format for kpi1 to kpi5.

I have 32 different KPIID with 32 different formats.

I hope my explanation make sense.

Solution
‎04-10-2014 03:24 PM
SAS Super FREQ
Posts: 8,719

Re: Different Background Colour in each printed line?

Hi:

  For some information about PROC REPORT and styles, this paper shows some of the style changes (https://support.sas.com/resources/papers/proceedings13/366-2013.pdf). For information about how PROC REPORT works, you might want to refer to the PROC REPORT  documentation. Changing Age based on name is an example in the above paper shown on page 13.

cynthia

Contributor alr
Contributor
Posts: 39

Re: Different Background Colour in each printed line?

Thank you Cynthia, I'll look at the paper.

Contributor alr
Contributor
Posts: 39

Re: Different Background Colour in each printed line?

Thank you both. It works:

proc report data=mydata;

   col kpiid kpi_4 kpi_3 kpi_2 kpi_1 kpi_0;

   define kpiid       / display  ;

   define kpi_0-kpi_4 / display  ;

   compute kpi_0;

      if kpiid = 1 then do;

         call define ('kpi_0','style','style={background=myfmt.}');

         call define ('kpi_1','style','style={background=myfmt.}');

         call define ('kpi_2','style','style={background=myfmt.}');

         call define ('kpi_3','style','style={background=myfmt.}');

         call define ('kpi_4','style','style={background=myfmt.}');

      end;

   endcomp;

run;

☑ This topic is SOLVED.

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

Discussion stats
  • 7 replies
  • 543 views
  • 3 likes
  • 3 in conversation