<?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-Color red/Green better/worse from month to month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Report-Color-red-Green-better-worse-from-month-to-month/m-p/876570#M346299</link>
    <description>&lt;P&gt;Hello&lt;BR /&gt;For each month there is a regression model that run and produce score (Y).&lt;BR /&gt;I would like to display the data set via proc report and apply a rule ad&lt;BR /&gt;S following:&lt;BR /&gt;If there is increase from one month to next month then color it in red.&lt;BR /&gt;If there is decrease from one month to next month then color it in green.&lt;BR /&gt;The calculation should be done for each row separately.&lt;BR /&gt;(Please note that green mean better explentaory variable or better resulted score)&lt;BR /&gt;(Please note that red mean worse explentaory variable or worse resulted score)&lt;BR /&gt;The colors will help the user (who look at the report) to understand if the customer had improvement or deterioration from one month to next month.&lt;BR /&gt;&lt;BR /&gt;Please note that number of columns with nameYYMM can be different .&lt;/P&gt;
&lt;P&gt;so i am looking for dynamic code that will work with any mumber of columns.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Input VAR_name $ Mon2301 Mon2302 Mon2303 Mon2304 Mon2305;
cards;
X1 70 70 70 70 70
X2 70 70 90 90 90
X3 40 40 40 40 40
X4 30 30 50 50 20
X5 70 45 45 45 45
X6 30 30 30 20 40
TOTAL 310 285 325 315 305
Y 7 6 9 9 7
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1684465366347.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/84120i8D40C0776B37AC77/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1684465366347.png" alt="Ronein_0-1684465366347.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 May 2023 03:03:16 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2023-05-19T03:03:16Z</dc:date>
    <item>
      <title>Proc Report-Color red/Green better/worse from month to month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Report-Color-red-Green-better-worse-from-month-to-month/m-p/876570#M346299</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;For each month there is a regression model that run and produce score (Y).&lt;BR /&gt;I would like to display the data set via proc report and apply a rule ad&lt;BR /&gt;S following:&lt;BR /&gt;If there is increase from one month to next month then color it in red.&lt;BR /&gt;If there is decrease from one month to next month then color it in green.&lt;BR /&gt;The calculation should be done for each row separately.&lt;BR /&gt;(Please note that green mean better explentaory variable or better resulted score)&lt;BR /&gt;(Please note that red mean worse explentaory variable or worse resulted score)&lt;BR /&gt;The colors will help the user (who look at the report) to understand if the customer had improvement or deterioration from one month to next month.&lt;BR /&gt;&lt;BR /&gt;Please note that number of columns with nameYYMM can be different .&lt;/P&gt;
&lt;P&gt;so i am looking for dynamic code that will work with any mumber of columns.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Input VAR_name $ Mon2301 Mon2302 Mon2303 Mon2304 Mon2305;
cards;
X1 70 70 70 70 70
X2 70 70 90 90 90
X3 40 40 40 40 40
X4 30 30 50 50 20
X5 70 45 45 45 45
X6 30 30 30 20 40
TOTAL 310 285 325 315 305
Y 7 6 9 9 7
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1684465366347.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/84120i8D40C0776B37AC77/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1684465366347.png" alt="Ronein_0-1684465366347.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 03:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Report-Color-red-Green-better-worse-from-month-to-month/m-p/876570#M346299</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-05-19T03:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report-Color red/Green better/worse from month to month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Report-Color-red-Green-better-worse-from-month-to-month/m-p/876643#M346326</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Input VAR_name $ Mon2301 Mon2302 Mon2303 Mon2304 Mon2305;
cards;
X1 70 70 70 70 70
X2 70 70 90 90 90
X3 40 40 40 40 40
X4 30 30 50 50 20
X5 70 45 45 45 45
X6 30 30 30 20 40
TOTAL 310 285 325 315 305
Y 7 6 9 9 7
;
Run;

proc transpose data=have(obs=0) out=vname;
var _all_;
run;
data _null_;
 set vname(firstobs=2) end=last;
length list $ 2000;
retain list;
list=catx(' ',list,_name_);
if last then do;
  call symputx('list',list);
  call symputx('last',_name_);
end;
run;

ods excel file='c:\temp\want.xlsx';
proc report data=have nowd;
define _all_/display;
compute &amp;amp;last.;
 array x{*} &amp;amp;list. ;
 do i=2 to dim(x);
   if x{i}&amp;gt;x{i-1} then call define(vname(x{i}),'style','style={background=red}');
   if x{i}&amp;lt;x{i-1} then call define(vname(x{i}),'style','style={background=green}');
 end;
endcomp;
run;
ods excel close;&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-1684497440603.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/84128iA22A48842C28F914/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1684497440603.png" alt="Ksharp_0-1684497440603.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 11:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Report-Color-red-Green-better-worse-from-month-to-month/m-p/876643#M346326</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-05-19T11:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report-Color red/Green better/worse from month to month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Report-Color-red-Green-better-worse-from-month-to-month/m-p/876741#M346354</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Can you please explain:&lt;/P&gt;
&lt;P&gt;The calculation is done on all columns except of the first column .&lt;/P&gt;
&lt;P&gt;You wrote compute only on the last column.&lt;/P&gt;
&lt;P&gt;How SAS know to perform computation on all columns (Except first)While you type computation only on last column?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;compute &amp;amp;last.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 May 2023 05:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Report-Color-red-Green-better-worse-from-month-to-month/m-p/876741#M346354</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-05-20T05:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report-Color red/Green better/worse from month to month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Report-Color-red-Green-better-worse-from-month-to-month/m-p/876744#M346355</link>
      <description>It is special character of PROC REPORT.&lt;BR /&gt;PROC REPORT calculated is from left to right and first to last.&lt;BR /&gt;Here I used "compute &amp;amp;last.;" which &amp;amp;last. is the last variable name, to make sure I can refer to any variable before &amp;amp;last.&lt;BR /&gt;if you use "compute var_name;" ,you only can refer to itself because there are not variables at left side of "var_name".&lt;BR /&gt;&lt;BR /&gt;So I use ARRAY to refer to Mon2301 Mon2302 Mon2303 Mon2304 Mon2305&lt;BR /&gt;"array x{*} &amp;amp;list. ;"&lt;BR /&gt;&lt;BR /&gt;do i=2 to dim(x);&lt;BR /&gt;means use "Mon2301 " (a.k.a x{1}) to compare with other variables to get the result you want and STYLE it by red or green.</description>
      <pubDate>Sat, 20 May 2023 09:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Report-Color-red-Green-better-worse-from-month-to-month/m-p/876744#M346355</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-05-20T09:05:54Z</dc:date>
    </item>
  </channel>
</rss>

