<?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: compute if then in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/651174#M22361</link>
    <description>thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21414"&gt;@ed&lt;/a&gt;_sas_memeber&lt;BR /&gt;&lt;BR /&gt;It would be a good solution, however my data adds new data on a daily basis (I'm using Year as a mock example, in reality they are Day, 60 of them),&lt;BR /&gt;so I guess it would be unpractical to hard code for all the cells.&lt;BR /&gt;&lt;BR /&gt;I've also tried to ad a fourth column to the dataset (not to be displayed in the report) indicating Y or N whether the sum matches or not, but I can't use it properly in the proc report...&lt;BR /&gt;&lt;BR /&gt;thanks&lt;BR /&gt;a "Year" on a daily basis (I'm using Year as a mock example, in reality they are Day) and have</description>
    <pubDate>Wed, 27 May 2020 18:42:33 GMT</pubDate>
    <dc:creator>MART1</dc:creator>
    <dc:date>2020-05-27T18:42:33Z</dc:date>
    <item>
      <title>Proc Report: compute if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/651148#M22359</link>
      <description>&lt;P&gt;Hello everybody&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to apply a format to some&amp;nbsp;cells in Proc Report based on their value (in the example I've provided, the TOT for&amp;nbsp;2010,2013,2015 and 2016 should be blue, while the&amp;nbsp;others remain white).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I'm using but I can't get it to work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data TEST;
	input YEAR EXPECTED MISSED TOTAL;
	datalines;

2010  10 20 30
2011  11 8 25
2012  9 15 11
2013  14 5 19
2014  5 8  11
2015  7 9 16
2016  10 1 11
2017  15 2 19
;
run;

proc report data=WORK.TEST nowd;
	column (YEAR, (EXPECTED MISSED TOTAL));
	define YEAR / across 'YEAR';
	define EXPECTED / analysis SUM 'EXP' missing;
	define MISSED / analysis SUM 'MISS' missing;
	define TOTAL / analysis SUM 'TOT' missing;

	compute YEAR;
		if EXPECTED + MISSED = TOTAL then
			do;
				do i = 3 to 24 by 3;
					call define(i,'style','style={background=lightblue}');
				end;
			end;
	endcomp;
run;

quit;&lt;/PRE&gt;&lt;P&gt;I've tried different combination of fields in the compute, but&amp;nbsp;I can't&amp;nbsp;get it to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;many thanks&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 17:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/651148#M22359</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2020-05-27T17:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report: compute if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/651167#M22360</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321375"&gt;@MART1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am afraid this does not work because "i" is not a macrovariable and you cannot refer directly to each new columns created by the "ACROSS" definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=WORK.TEST nowd;
	column (YEAR, (EXPECTED MISSED TOTAL));
	define YEAR / across 'YEAR';
	define EXPECTED / analysis SUM 'EXP' missing;
	define MISSED / analysis SUM 'MISS' missing;
	define TOTAL / analysis SUM 'TOT' missing;
	compute YEAR;
		if (_C1_ + _c2_) = _c3_ then call define('_c3_','style','style={background=lightblue}');
		if (_C4_ + _c6_) = _c6_ then call define('_c6_','style','style={background=lightblue}');
		if (_C7_ + _c8_) = _c9_ then call define('_c9_','style','style={background=lightblue}');
		if (_C10_ + _c11_) = _c12_ then call define('_c12_','style','style={background=lightblue}');
		if (_C13_ + _c14_) = _c15_ then call define('_c15_','style','style={background=lightblue}');
		if (_C16_ + _c17_) = _c18_ then call define('_c18_','style','style={background=lightblue}');
		if (_C19_ + _c20_) = _c21_ then call define('_c21_','style','style={background=lightblue}');
		if (_C22_ + _c23_) = _c24_ then call define('_c24_','style','style={background=lightblue}');
	endcomp;
run;&lt;/CODE&gt;&lt;/PRE&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 d’écran 2020-05-27 à 20.27.03.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40050i112B6689F3A1F564/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture d’écran 2020-05-27 à 20.27.03.png" alt="Capture d’écran 2020-05-27 à 20.27.03.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 18:27:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/651167#M22360</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-27T18:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report: compute if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/651174#M22361</link>
      <description>thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21414"&gt;@ed&lt;/a&gt;_sas_memeber&lt;BR /&gt;&lt;BR /&gt;It would be a good solution, however my data adds new data on a daily basis (I'm using Year as a mock example, in reality they are Day, 60 of them),&lt;BR /&gt;so I guess it would be unpractical to hard code for all the cells.&lt;BR /&gt;&lt;BR /&gt;I've also tried to ad a fourth column to the dataset (not to be displayed in the report) indicating Y or N whether the sum matches or not, but I can't use it properly in the proc report...&lt;BR /&gt;&lt;BR /&gt;thanks&lt;BR /&gt;a "Year" on a daily basis (I'm using Year as a mock example, in reality they are Day) and have</description>
      <pubDate>Wed, 27 May 2020 18:42:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/651174#M22361</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2020-05-27T18:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report: compute if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/651178#M22362</link>
      <description>In this case, maybe a PROC TABULATE could be a more flexible solution?</description>
      <pubDate>Wed, 27 May 2020 18:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/651178#M22362</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-27T18:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report: compute if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/652467#M22458</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can I just ask one more thing about the solution you have proposed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I need to fill the background of a different cell rather than the last one in the group&lt;/P&gt;&lt;P&gt;i.e.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IF C1 &amp;nbsp;&amp;lt;&amp;gt; &amp;nbsp;(C2+C3)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;I need to colour C2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it does not work, as it fills the cell regardless&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is an example&lt;/P&gt;&lt;PRE&gt;data TEST;
	input YEAR COL1 COL2 COL3;
	datalines;

2016 30 0 30
2017 20 10 9
2018 5 2 3
2019 10 4 4
2020 15 7 8
2021 5 0 5
;
run;

title "colour COL2 red if COL1 &amp;lt;&amp;gt; COL2+COL3";
proc report data=WORK.TEST nowd;
	column (YEAR, (COL1 COL2 COL3));
	define YEAR / across 'YEAR';
	define COL1 / analysis SUM 'COL1' missing;
	define COL2 / analysis SUM 'COL2' missing;
	define COL3 / analysis SUM 'COL3' missing;
	compute YEAR;

		if  _C1_ ne (_C2_ + _C3_) then call define('_c2_','style','style={background=red}');
		if  _C4_ ne (_C5_ + _C6_) then call define('_c5_','style','style={background=red}');
		if  _C7_ ne (_C8_ + _C9_) then call define('_c8_','style','style={background=red}');
		if  _C10_ ne (_C11_ + _C12_) then call define('_c11_','style','style={background=red}');
		if  _C13_ ne (_C14_ + _C15_) then call define('_c14_','style','style={background=red}');
		if  _C16_ ne (_C17_ + _C18_) then call define('_c17_','style','style={background=red}');

	endcomp;
run;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="sas ex.png" style="width: 852px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40257iB6D1BE1B423943A5/image-dimensions/852x112?v=v2" width="852" height="112" role="button" title="sas ex.png" alt="sas ex.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any rule / and a wokaround for this?&lt;/P&gt;&lt;P&gt;(it seems that only the "define" can only be applied to the last cell in the group?)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 09:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/652467#M22458</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2020-06-02T09:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report: compute if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/652591#M22459</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321375"&gt;@MART1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue seems to come from the way to specify the condition. E.g. &amp;nbsp;&lt;CODE class=" language-sas"&gt;_C1_ ne (_C2_ + _C3_)&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;It works if you put this instead:&amp;nbsp;&lt;CODE class=" language-sas"&gt;abs(_C1_ - (_C2_ + _C3_)) &amp;gt; 0&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Very weird indeed&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":face_with_rolling_eyes:"&gt;🙄&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEST;
	input YEAR COL1 COL2 COL3;
	datalines;

2016 30 0 30
2017 20 10 9
2018 5 2 3
2019 10 4 4
2020 15 7 8
2021 5 0 5
;
run;

title "colour COL2 red if COL1 &amp;lt;&amp;gt; COL2+COL3";

proc report data=WORK.TEST nowd;
	column (YEAR, (COL1 COL2 COL3));
	define YEAR / across;
	define COL1 / analysis SUM missing;
	define COL2 / analysis SUM missing;
	define COL3 / analysis SUM missing;
	compute year;
		if  abs(_C1_ - (_C2_ + _C3_)) &amp;gt; 0 then call define('_c2_','style','style={background=red}');
		if  abs(_C4_ - (_C5_ + _C6_)) &amp;gt; 0 then call define('_c5_','style','style={background=red}');
		if  abs(_C7_ - (_C8_ + _C9_)) &amp;gt; 0 then call define('_c8_','style','style={background=red}');
		if  abs(_C10_ - (_C11_ + _C12_)) &amp;gt; 0 then call define('_c11_','style','style={background=red}');
		if  abs(_C13_ - (_C14_ + _C15_)) &amp;gt; 0 then call define('_c14_','style','style={background=red}');
		if  abs(_C16_ - (_C17_ + _C18_)) &amp;gt; 0 then call define('_c17_','style','style={background=red}');
	endcomp;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output: &lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2020-06-02 à 17.31.00.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40271iF729B9D0794DAF0E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture d’écran 2020-06-02 à 17.31.00.png" alt="Capture d’écran 2020-06-02 à 17.31.00.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 15:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/652591#M22459</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-06-02T15:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report: compute if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/652833#M22463</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321375"&gt;@MART1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option is just to put&amp;nbsp;&amp;nbsp;"compute COL3;" instead of&amp;nbsp;&amp;nbsp;"compute YEAR;"&lt;/P&gt;
&lt;P&gt;All the best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;title "colour COL2 red if COL1 &amp;lt;&amp;gt; COL2+COL3";
proc report data=WORK.TEST nowd;
	column (YEAR, (COL1 COL2 COL3));
	define YEAR / across 'YEAR';
	define COL1 / analysis SUM 'COL1' missing;
	define COL2 / analysis SUM 'COL2' missing;
	define COL3 / analysis SUM 'COL3' missing;
	compute COL3;

		if  _C1_ ne (_C2_ + _C3_) then call define('_c2_','style','style={background=red}');
		if  _C4_ ne (_C5_ + _C6_) then call define('_c5_','style','style={background=red}');
		if  _C7_ ne (_C8_ + _C9_) then call define('_c8_','style','style={background=red}');
		if  _C10_ ne (_C11_ + _C12_) then call define('_c11_','style','style={background=red}');
		if  _C13_ ne (_C14_ + _C15_) then call define('_c14_','style','style={background=red}');
		if  _C16_ ne (_C17_ + _C18_) then call define('_c17_','style','style={background=red}');

	endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jun 2020 11:47:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/652833#M22463</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-06-03T11:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report: compute if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/654556#M22540</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;weird indeed, it&amp;nbsp;can handle a more complex math operation but not the simple one!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But your&amp;nbsp;version works a treat, very helpful many thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 15:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/654556#M22540</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2020-06-08T15:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report: compute if then</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/654559#M22541</link>
      <description>&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN class="token function keyword"&gt;PS: I have incorrectly tagged my post a solution &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN class="token function keyword"&gt;The solution is&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN class="token function keyword"&gt;abs&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;_C1_ &lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;_C2_ &lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt; _C3_&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 15:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Report-compute-if-then/m-p/654559#M22541</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2020-06-08T15:13:23Z</dc:date>
    </item>
  </channel>
</rss>

