View previous topic :: View next topic
|
Author |
Message |
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Hi,
I have a requirement to generate a report from the below input, using SAS.
Code: |
Hour Count
1 3
2 4
3 5
4 1 |
the expected output is in the attachment. I understand that many people are unable to see attachments, but I don't know any other way to format & show the expected output.
Could you let me know how this could be done. I am aware that a cell can be highlighted by using style element, but dont know how to split a single cell into 5 subcells.
the maximum value of count is 5.
Thanks & Regards, |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
If you have SAS/GRAPH, this is simply one of the options of PROC CHART (look at HBAR). If you do not have SAS/GRAPH, you can generate a similar report yourself by using nested IF statements or SELECT-WHEN in your DATA step. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Using ODS you can change the background colour of the cells depending on the number.
I've done something very similar in the past and don't have access to the code at work
Will try and post it later this evening if I remember
The theory is that you have 5 cells, not one that has been sub divided and do the change for 1 through n and then leave the rest as default background, or set it to default as a precaution as I believe it sets the value for following cells in the column.
Lucky you - I can access the code from my mobile
Code: |
If condition then call define(_COL_,"style","style=[backgroundcolor=yellow]");
else ........... define it another colour |
|
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Nice.. Thank you Rober & Expat.
I will take this idea and try implementing in the reporting part.
Regards, |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Finally found the right code
The cell background is changed via a compute in the ODS process.
Code: |
compute CA13;
if CL13 LE 1 then call define(_col_,"style","style=[backgroundcolor=yellow]");
else call define(_col_,"style","style=[backgroundcolor=lightblue]");
endcomp;
compute CA12;
if CL12 LE 1 then call define(_COL_,"style","style=[backgroundcolor=yellow]");
else call define(_COL_,"style","style=[backgroundcolor=lightblue]");
endcomp;
|
|
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Thank you again. This would make a fine enhancement to the PROC REPORT. :-) |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Just one point that took me forever and an age to find out using Trial and lots of Error ....
If you use a control variable like I did CL13 / CL12
Code: |
/* Change background colour of cells depending on a different variable - - -
- - - Include the control variables in the output, but define them as NOPRINT
- - - ALSO - PLACE THE CONTROL VARIABLES BEFORE THE DISPLAY VARIABLES IN THE COLUMN STATEMENT */
compute CA13;
if CL13 LE 1 then call define(_col_,"style","style=[backgroundcolor=yellow]");
else call define(_col_,"style","style=[backgroundcolor=lightblue]");
endcomp;
compute CA12;
if CL12 LE 1 then call define(_COL_,"style","style=[backgroundcolor=yellow]");
else call define(_COL_,"style","style=[backgroundcolor=lightblue]");
endcomp;
|
|
|
Back to top |
|
|
|