<?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: PROC REPORT, compare to value in first row in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646372#M24066</link>
    <description>&lt;P&gt;One shot .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sashelp.class nowd;
columns name sex age height weight;
define name /display;
define sex/display;
define age/display;
define height/analysis mean format=12.1;
define weight/analysis mean format=12.1;
compute before;
name='AVG:'; avg_height=height.mean;
endcomp;
compute height;
if height.mean&amp;gt;avg_height and missing(_break_) 
then call define(_col_,'style','style={background=yellow}');
endcomp;
rbreak before /summarize ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 09 May 2020 12:04:27 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-05-09T12:04:27Z</dc:date>
    <item>
      <title>PROC REPORT, compare to value in first row</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646189#M24051</link>
      <description>&lt;P&gt;Suppose I have a SAS data set where the first row is an overall average (see data set named CLASS in the example below). I then want to use PROC REPORT to display all the rows and compare a variable to the overall average in the first row and have PROC REPORT highlight the row if the variable is greater than the average. How can I do this?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=sashelp.class;
	var height weight;
	output out=class_means mean=;
run;
data class;
	set class_means(keep=height weight) sashelp.class;
run;
proc report data=class;
    columns name sex age height weight;
	define name / display missing;
	define sex / display missing;
	define age / display missing;
	define height/display format=5.1;
	define weight/display format=5.1;
	compute name;
	    if missing(name) then name='Avg';
	endcompute;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Desired output, the heights that are greater than the average are shown with yellow background, how can I get PROC REPORT to do this?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 260px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39213i48F2EB643101010E/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;I know how to turn individual cells to have a certain background color, I don't know how to write an IF statement in the PROC REPORT compute block that compares the value in the cell to the value in the first row.&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 13:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646189#M24051</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-08T13:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT, compare to value in first row</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646196#M24052</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; You were very close. You just needed a few things. Just as you changed the value of the NAME column to be Avg, you can use that value in a COMPUTE block for WEIGHT to grab and save the values on that row. Then you can use the temporary helper variables in IF statements to test:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1588943346450.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39214i116D8D7F50DFF1A7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1588943346450.png" alt="Cynthia_sas_0-1588943346450.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; If you don't want to use helper/temporary variables in PROC REPORT, then an alternate approach is to massage the data in your DATA step program to make your helper variables and use NOPRINT in the PROC REPORT step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=sashelp.class;
	var height weight;
	output out=class_means mean=holdavg_h holdavg_w;
run;
 
data class;
    if _n_ = 1 then set class_means(keep=holdavg_h holdavg_w);
	retain holdavg_h holdavg_w;
	set sashelp.class;
	ord = _n_;
	if _n_ = 1 then name='Avg';
run;

proc report data=class;
    columns ord name sex age holdavg_h holdavg_w height weight;
	define ord / order noprint;
	define name / display missing;
	define sex / display missing;
	define age / display missing;
	define holdavg_h/display format=5.1 noprint;
	define holdavg_w/display format=5.1 noprint;
	define height/display format=5.1;
	define weight/display format=5.1;
	compute weight;
	    if height gt holdavg_h then
	       call define('height','style','style={background=yellow}');
	    if weight lt holdavg_w then
	       call define(_col_,'style','style={background=lightblue}');
	endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Either approach will work. Just depends on your preference.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 19:13:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646196#M24052</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-05-08T19:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT, compare to value in first row</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646200#M24053</link>
      <description>&lt;P&gt;After your output of class_means, can you create a macro variable for the mean you want to compare it to. Then create a format with proc format using that macro variable as a cutoff in your value statement. Similar to the pattern on page 9-10 of this&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings13/366-2013.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings13/366-2013.pdf&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 13:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646200#M24053</guid>
      <dc:creator>bobpep212</dc:creator>
      <dc:date>2020-05-08T13:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT, compare to value in first row</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646213#M24054</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;, I have done the second method, but it bothered me to have to create a new variable which has a constant value in my data step just to do this comparison. I think in the future, I will use your first method.&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 13:57:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646213#M24054</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-08T13:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT, compare to value in first row</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646372#M24066</link>
      <description>&lt;P&gt;One shot .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sashelp.class nowd;
columns name sex age height weight;
define name /display;
define sex/display;
define age/display;
define height/analysis mean format=12.1;
define weight/analysis mean format=12.1;
compute before;
name='AVG:'; avg_height=height.mean;
endcomp;
compute height;
if height.mean&amp;gt;avg_height and missing(_break_) 
then call define(_col_,'style','style={background=yellow}');
endcomp;
rbreak before /summarize ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 May 2020 12:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646372#M24066</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-05-09T12:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT, compare to value in first row</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646373#M24067</link>
      <description>&lt;P&gt;Well that's impressive taht you can do this all in one PROC. There are soooo many features in PROC REPORT, I'm surprised SAS had the time to program them all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, one command I do not understand:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if height.mean&amp;gt;avg_height and missing(_break_) 
then call define(_col_,'style','style={background=yellow}');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would think you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if height &amp;gt; avg_height and missing(_break_) then ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but this doesn't work. Could you explain that part?&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 12:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646373#M24067</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-09T12:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT, compare to value in first row</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646389#M24069</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt;When you use a statistic in a DEFINE statement for a numeric variable, such as:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;define &lt;FONT color="#0000FF"&gt;var1&lt;/FONT&gt; / &lt;FONT color="#FF00FF"&gt;sum&lt;/FONT&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;define &lt;FONT color="#0000FF"&gt;var2&lt;/FONT&gt; / analysis &lt;FONT color="#FF00FF"&gt;sum&lt;/FONT&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;define &lt;FONT color="#0000FF"&gt;var3&lt;/FONT&gt; / &lt;FONT color="#FF00FF"&gt;mean&lt;/FONT&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;define &lt;FONT color="#0000FF"&gt;var4&lt;/FONT&gt; / analysis &lt;FONT color="#FF00FF"&gt;mean&lt;/FONT&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;Then you need to use the "compound name" of the variable in a COMPUTE block. That compound name is &lt;FONT face="comic sans ms,sans-serif"&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;variable&lt;/FONT&gt;.&lt;FONT color="#FF00FF"&gt;statistic&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/FONT&gt; -- and for the above 4 define statements would be:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;var1&lt;/FONT&gt;.&lt;FONT color="#FF00FF"&gt;sum&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;var2&lt;/FONT&gt;.&lt;FONT color="#FF00FF"&gt;sum&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;var3&lt;/FONT&gt;.&lt;FONT color="#FF00FF"&gt;mean&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;var4&lt;/FONT&gt;.&lt;FONT color="#FF00FF"&gt;mean&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;This compound name requirement does NOT apply to numeric variables used as GROUP, ORDER, DISPLAY or aliased items, but using DISPLAY for a numeric item also turns off summarizing at a break. I frequently use DISPLAY for variables like AGE or DATE, but always use SUM for variables like AMOUNT and SALES (as examples) because I usually want to summarize variables like AMOUNT and SALES, but NOT summarize variables like AGE or DATE.&lt;BR /&gt;&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 14:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646389#M24069</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-05-09T14:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT, compare to value in first row</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646392#M24070</link>
      <description>&lt;P&gt;So in the example from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; he is using &lt;FONT face="courier new,courier"&gt;define height/analysis mean;&lt;/FONT&gt; which obtains the "mean" of a single value, which is that single value. What I used &lt;FONT face="courier new,courier"&gt;define height/display;&lt;/FONT&gt; doesn't compute a mean, and isn't going to work in the example from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; . I guess I need to let this information sink in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 15:51:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646392#M24070</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-09T15:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT, compare to value in first row</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646489#M24073</link>
      <description>Use this code&lt;BR /&gt;proc report data=sashelp.class nowd out=check ;&lt;BR /&gt;&lt;BR /&gt;You are going to find a variable named _BREAK_ .</description>
      <pubDate>Sun, 10 May 2020 10:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-compare-to-value-in-first-row/m-p/646489#M24073</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-05-10T10:45:35Z</dc:date>
    </item>
  </channel>
</rss>

