<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to assign colors to a column according to another column in PROC REPORT in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726515#M225746</link>
    <description>Thanks for your help!</description>
    <pubDate>Mon, 15 Mar 2021 19:32:45 GMT</pubDate>
    <dc:creator>Relax</dc:creator>
    <dc:date>2021-03-15T19:32:45Z</dc:date>
    <item>
      <title>How to assign colors to a column according to another column in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726503#M225742</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I have a small sample dataset, which has three variables, ID, Grade and Result.&amp;nbsp; I want to report this dataset using PROC Report and assign the different colors to Grade based on the value of variable Result.&amp;nbsp; Let's say, if Result is Pass then the background color of Grade is green; otherwise, it would be in red.&amp;nbsp; At the same time, I only want to see ID and Grade in the output, so I use NOPRINT for Result.&amp;nbsp; Here is my code:&lt;/P&gt;&lt;P&gt;DATA WORK.Test;&lt;BR /&gt;INFILE DATALINES;&lt;BR /&gt;INPUT ID Grade Result $;&lt;BR /&gt;DATALINES;&lt;BR /&gt;1 90 Pass&lt;BR /&gt;2 65 Pass&lt;BR /&gt;3 57 Fail&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC REPORT DATA=WORK.Test&lt;BR /&gt;STYLE(REPORT) = {OUTPUTWIDTH=60%}&lt;BR /&gt;STYLE(HEADER) = [JUST = CENTER FONT_FACE = calibri FONT_SIZE = 3 FOREGROUND = Black BACKGROUND = Orange PROTECTSPECIALCHARS=OFF];&lt;BR /&gt;COLUMN ID Grade Result;&lt;BR /&gt;DEFINE ID / DISPLAY STYLE(COLUMN)=[JUST=l FONT_FACE = calibri FONT_SIZE = 3];&lt;BR /&gt;DEFINE Grade / DISPLAY STYLE(COLUMN)=[JUST=l FONT_FACE = calibri FONT_SIZE = 3];&lt;BR /&gt;DEFINE Result / NOPRINT STYLE(COLUMN)=[JUST=l FONT_FACE = calibri FONT_SIZE = 3];&lt;BR /&gt;COMPUTE Grade;&lt;BR /&gt;IF Result = 'Pass' THEN CALL DEFINE("_COL_", "STYLE", "STYLE={BACKGROUND=CX00FF00}");&lt;BR /&gt;IF Result = 'Fail' THEN CALL DEFINE("_COL_", "STYLE", "STYLE={BACKGROUND=CXFF0000}");&lt;BR /&gt;ENDCOMP;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;The output I want is&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Relax_0-1615833805805.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55977i16C95FE5E2D09535/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Relax_0-1615833805805.png" alt="Relax_0-1615833805805.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Could someone kindly help me figure out how to do it?&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 18:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726503#M225742</guid>
      <dc:creator>Relax</dc:creator>
      <dc:date>2021-03-15T18:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign colors to a column according to another column in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726513#M225745</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;PROC REPORT DATA=WORK.Test
STYLE(REPORT) = {OUTPUTWIDTH=60%}
STYLE(HEADER) = [JUST = CENTER FONT_FACE = calibri FONT_SIZE = 3 FOREGROUND = Black BACKGROUND = Orange PROTECTSPECIALCHARS=OFF];
COLUMN ID Result Grade ;
DEFINE ID / DISPLAY STYLE(COLUMN)=[JUST=l FONT_FACE = calibri FONT_SIZE = 3];
DEFINE Grade / DISPLAY STYLE(COLUMN)=[JUST=l FONT_FACE = calibri FONT_SIZE = 3];
DEFINE Result / NOPRINT STYLE(COLUMN)=[JUST=l FONT_FACE = calibri FONT_SIZE = 3];
COMPUTE Grade;
IF Result = 'Pass' THEN CALL DEFINE(_COL_, "STYLE", "STYLE={BACKGROUND=CX00FF00}");
IF Result = 'Fail' THEN CALL DEFINE(_COL_, "STYLE", "STYLE={BACKGROUND=CXFF0000}");
ENDCOMP;
QUIT;&lt;/PRE&gt;
&lt;P&gt;Two things to change:&lt;/P&gt;
&lt;P&gt;Column order. Proc Report builds report items from left to right. So the column Grade can't see Result if the Result column is to the right on the Columns statement.&lt;/P&gt;
&lt;P&gt;Second, _col_ is a key word. When you place it in quotes then it becomes a value, which doesn't match the requirement for call define statements.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 19:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726513#M225745</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-15T19:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign colors to a column according to another column in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726515#M225746</link>
      <description>Thanks for your help!</description>
      <pubDate>Mon, 15 Mar 2021 19:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726515#M225746</guid>
      <dc:creator>Relax</dc:creator>
      <dc:date>2021-03-15T19:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign colors to a column according to another column in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726517#M225748</link>
      <description>&lt;P&gt;This seems to work as well, though&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; has identified the root of the issue - that one often catches me as well with CALL DEFINE.&lt;/P&gt;
&lt;P&gt;This uses the option to explicitly name the column being shaded rather than it being implicit, which I personally prefer as it makes the code slightly more legible IMO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC REPORT DATA=WORK.Test
STYLE(REPORT) = {OUTPUTWIDTH=60%}
STYLE(HEADER) = [JUST = CENTER FONT_FACE = calibri FONT_SIZE = 3 FOREGROUND = Black BACKGROUND = Orange PROTECTSPECIALCHARS=OFF];
COLUMN ID Grade Result;
DEFINE ID / DISPLAY STYLE(COLUMN)=[JUST=l FONT_FACE = calibri FONT_SIZE = 3];
DEFINE Grade / DISPLAY STYLE(COLUMN)=[JUST=l FONT_FACE = calibri FONT_SIZE = 3];
DEFINE Result / NOPRINT STYLE(COLUMN)=[JUST=l FONT_FACE = calibri FONT_SIZE = 3];
COMPUTE Result;
IF Result ="Pass" THEN  CALL DEFINE("grade", "style", "style=[background=CX00FF00]");
else IF Result="Fail" THEN  CALL DEFINE("grade", "style", "style=[background=CXFF0000]"); 
ENDCOMP;
QUIT;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222207"&gt;@Relax&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello All,&lt;/P&gt;
&lt;P&gt;I have a small sample dataset, which has three variables, ID, Grade and Result.&amp;nbsp; I want to report this dataset using PROC Report and assign the different colors to Grade based on the value of variable Result.&amp;nbsp; Let's say, if Result is Pass then the background color of Grade is green; otherwise, it would be in red.&amp;nbsp; At the same time, I only want to see ID and Grade in the output, so I use NOPRINT for Result.&amp;nbsp; Here is my code:&lt;/P&gt;
&lt;P&gt;DATA WORK.Test;&lt;BR /&gt;INFILE DATALINES;&lt;BR /&gt;INPUT ID Grade Result $;&lt;BR /&gt;DATALINES;&lt;BR /&gt;1 90 Pass&lt;BR /&gt;2 65 Pass&lt;BR /&gt;3 57 Fail&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;PROC REPORT DATA=WORK.Test&lt;BR /&gt;STYLE(REPORT) = {OUTPUTWIDTH=60%}&lt;BR /&gt;STYLE(HEADER) = [JUST = CENTER FONT_FACE = calibri FONT_SIZE = 3 FOREGROUND = Black BACKGROUND = Orange PROTECTSPECIALCHARS=OFF];&lt;BR /&gt;COLUMN ID Grade Result;&lt;BR /&gt;DEFINE ID / DISPLAY STYLE(COLUMN)=[JUST=l FONT_FACE = calibri FONT_SIZE = 3];&lt;BR /&gt;DEFINE Grade / DISPLAY STYLE(COLUMN)=[JUST=l FONT_FACE = calibri FONT_SIZE = 3];&lt;BR /&gt;DEFINE Result / NOPRINT STYLE(COLUMN)=[JUST=l FONT_FACE = calibri FONT_SIZE = 3];&lt;BR /&gt;COMPUTE Grade;&lt;BR /&gt;IF Result = 'Pass' THEN CALL DEFINE("_COL_", "STYLE", "STYLE={BACKGROUND=CX00FF00}");&lt;BR /&gt;IF Result = 'Fail' THEN CALL DEFINE("_COL_", "STYLE", "STYLE={BACKGROUND=CXFF0000}");&lt;BR /&gt;ENDCOMP;&lt;BR /&gt;QUIT;&lt;/P&gt;
&lt;P&gt;The output I want is&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Relax_0-1615833805805.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55977i16C95FE5E2D09535/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Relax_0-1615833805805.png" alt="Relax_0-1615833805805.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Could someone kindly help me figure out how to do it?&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 19:35:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726517#M225748</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-15T19:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign colors to a column according to another column in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726526#M225753</link>
      <description>&lt;P&gt;Dig it.&amp;nbsp; Thanks for showing me one more option!&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 20:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726526#M225753</guid>
      <dc:creator>Relax</dc:creator>
      <dc:date>2021-03-15T20:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign colors to a column according to another column in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726531#M225757</link>
      <description>Note that in this case, the order doesn't matter as well &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;</description>
      <pubDate>Mon, 15 Mar 2021 20:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726531#M225757</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-15T20:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign colors to a column according to another column in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726534#M225759</link>
      <description>&lt;P&gt;Yes, I noticed that.&amp;nbsp; So it may be easier for me to memorize and practice it the next time when I use PROC Report&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 20:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-colors-to-a-column-according-to-another-column-in/m-p/726534#M225759</guid>
      <dc:creator>Relax</dc:creator>
      <dc:date>2021-03-15T20:36:23Z</dc:date>
    </item>
  </channel>
</rss>

