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?
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
Hi,
Yes, you need a compute section and a call style command in proc report. Here are some examples:
Thank you.
Is it possible to compute a group of variables?
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.
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.
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
Thank you Cynthia, I'll look at the paper.
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;
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.