<?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 PROC REPORT — how to test group variable value in COMPUTE block? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-how-to-test-group-variable-value-in-COMPUTE-block/m-p/749510#M235535</link>
    <description>&lt;P&gt;Here's a simple example of what I am trying to do, using a modified version of SASHELP.CLASS. Note that there are now both a male and female in the class named "Lindsay", and in my PROC REPORT, I want to just highlight the male "Lindsay" but not the female "Lindsay".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, the problem is: How can I do the test in the COMPUTE block to only highlight the male "Lindsay" since the column SEX is blank for this person?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class; /* My modified version of SASHELP.CLASS */
    set sashelp.class;
    if name='Alice' then name='Lindsay';
    if name='Jeffrey' then name='Lindsay';
run;

proc report data=class;
    columns sex name age height weight;
    define sex/group;
    compute name;
         if sex='M' and name='Alfred' then call define('name','style','style={background=yellow}');
         if sex='M' and name='Lindsay' then call define('name','style','style={background=orange}');
    endcompute;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can see that in the output, Alfred has a yellow background, the code works. But the male Lindsay doesn't get an orange background because the value of SEX in a group variable is blank in the table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 282px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60607i479DBDA0732F06AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Jun 2021 12:52:21 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-06-22T12:52:21Z</dc:date>
    <item>
      <title>PROC REPORT — how to test group variable value in COMPUTE block?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-how-to-test-group-variable-value-in-COMPUTE-block/m-p/749510#M235535</link>
      <description>&lt;P&gt;Here's a simple example of what I am trying to do, using a modified version of SASHELP.CLASS. Note that there are now both a male and female in the class named "Lindsay", and in my PROC REPORT, I want to just highlight the male "Lindsay" but not the female "Lindsay".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, the problem is: How can I do the test in the COMPUTE block to only highlight the male "Lindsay" since the column SEX is blank for this person?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class; /* My modified version of SASHELP.CLASS */
    set sashelp.class;
    if name='Alice' then name='Lindsay';
    if name='Jeffrey' then name='Lindsay';
run;

proc report data=class;
    columns sex name age height weight;
    define sex/group;
    compute name;
         if sex='M' and name='Alfred' then call define('name','style','style={background=yellow}');
         if sex='M' and name='Lindsay' then call define('name','style','style={background=orange}');
    endcompute;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can see that in the output, Alfred has a yellow background, the code works. But the male Lindsay doesn't get an orange background because the value of SEX in a group variable is blank in the table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 282px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60607i479DBDA0732F06AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 12:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-how-to-test-group-variable-value-in-COMPUTE-block/m-p/749510#M235535</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-22T12:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT — how to test group variable value in COMPUTE block?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-how-to-test-group-variable-value-in-COMPUTE-block/m-p/749525#M235546</link>
      <description>&lt;P&gt;It is so interesting question . It is more like a bug .&lt;/P&gt;
&lt;P&gt;Using a temp variable to hold SEX value and could get solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class; /* My modified version of SASHELP.CLASS */
    set sashelp.class;
    if name='Alice' then name='Lindsay';
    if name='Jeffrey' then name='Lindsay';
run;

proc report data=class nowd out=temp;
    columns sex name age height weight;
    define sex/group;

	compute before sex;
     _s=sex;
	endcomp;

    compute name;
         if _s='M' and name='Alfred' then call define('name','style','style={background=yellow}');
         if _s='M' and name='Lindsay' then call define('name','style','style={background=red}');
    endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1624368216366.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60609i015DB2D419F98FD0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1624368216366.png" alt="Ksharp_0-1624368216366.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 13:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-how-to-test-group-variable-value-in-COMPUTE-block/m-p/749525#M235546</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-06-22T13:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT — how to test group variable value in COMPUTE block?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-how-to-test-group-variable-value-in-COMPUTE-block/m-p/749526#M235547</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;. I think I had run into this once before, as your solution looks familiar, but anyway I couldn't figure out how to do this, so now I know.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 13:28:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-how-to-test-group-variable-value-in-COMPUTE-block/m-p/749526#M235547</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-22T13:28:44Z</dc:date>
    </item>
  </channel>
</rss>

