<?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: ODS Excel- conditional sheet tab color in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/ODS-Excel-conditional-sheet-tab-color/m-p/966546#M376155</link>
    <description>&lt;PRE&gt; 
proc sql  noprint;
select case when max(invoice)&amp;gt;30000 then 'red ' else 'green' end  as Ind_max_invoice_Gt_30K  into :Ind_max_invoice_Gt_30K
from sashelp.cars
where Make="Honda"
;
quit;


ods excel file="c:\temp\Honda_Report.xlsx" 
options  (sheet_name='Honda'
embedded_titles='yes' 
embedded_footnotes='yes'
sheet_interval="proc" 
gridlines = 'yes'
zoom='50'
tab_color="&amp;amp;Ind_max_invoice_Gt_30K."  /*Change TAB Color based on macro var  Ind_max_invoice_Gt_30K  :  if =1 then Red , else Green*/
);
title 'Honda_Report';
proc report data=sashelp.cars contents="Honda Cars" nowd;
	  where Make="Honda";
	  column ("Car" make model) ("Cost" msrp invoice) 
           ("Fuel Efficiency" mpg_city mpg_highway);  
run;
ods excel  close;&lt;/PRE&gt;</description>
    <pubDate>Thu, 15 May 2025 09:43:24 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2025-05-15T09:43:24Z</dc:date>
    <item>
      <title>ODS Excel- conditional sheet tab color</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ODS-Excel-conditional-sheet-tab-color/m-p/966545#M376154</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am using ODS excel to export report into excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to color the sheet tab name based on a macro variable:&lt;/P&gt;
&lt;P&gt;if there is an invoice&amp;gt;30,000 then sheet tab color be red, else be green.&lt;/P&gt;
&lt;P&gt;So, as I understand need to define&amp;nbsp; proc format that get color value based on the macro var.&lt;/P&gt;
&lt;P&gt;What is the way to do it please???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
 
proc sql  noprint;
select max(case when invoice&amp;gt;30000 then 1 else 0 end ) as Ind_max_invoice_Gt_30K  into :Ind_max_invoice_Gt_30K
from sashelp.cars
where Make="Honda"
;
quit;

ods excel file="/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/Honda_Report.xlsx" 
options  (sheet_name='Honda'
embedded_titles='yes' 
embedded_footnotes='yes'
sheet_interval="proc" 
gridlines = 'yes'
zoom='50'
&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;tab_color=&amp;amp;Color_Fmt.&lt;/FONT&gt; &lt;/STRONG&gt; /*Change TAB Color based on macro var  Ind_max_invoice_Gt_30K  :  if =1 then Red , else Green*/
);
title 'Honda_Report';
proc report data=sashelp.cars contents="Honda Cars";
	  where Make="Honda";
	  column ("Car" make model) ("Cost" msrp invoice) 
           ("Fuel Efficiency" mpg_city mpg_highway);  
run;
ods excel  close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 08:50:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ODS-Excel-conditional-sheet-tab-color/m-p/966545#M376154</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-05-15T08:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: ODS Excel- conditional sheet tab color</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ODS-Excel-conditional-sheet-tab-color/m-p/966546#M376155</link>
      <description>&lt;PRE&gt; 
proc sql  noprint;
select case when max(invoice)&amp;gt;30000 then 'red ' else 'green' end  as Ind_max_invoice_Gt_30K  into :Ind_max_invoice_Gt_30K
from sashelp.cars
where Make="Honda"
;
quit;


ods excel file="c:\temp\Honda_Report.xlsx" 
options  (sheet_name='Honda'
embedded_titles='yes' 
embedded_footnotes='yes'
sheet_interval="proc" 
gridlines = 'yes'
zoom='50'
tab_color="&amp;amp;Ind_max_invoice_Gt_30K."  /*Change TAB Color based on macro var  Ind_max_invoice_Gt_30K  :  if =1 then Red , else Green*/
);
title 'Honda_Report';
proc report data=sashelp.cars contents="Honda Cars" nowd;
	  where Make="Honda";
	  column ("Car" make model) ("Cost" msrp invoice) 
           ("Fuel Efficiency" mpg_city mpg_highway);  
run;
ods excel  close;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 May 2025 09:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ODS-Excel-conditional-sheet-tab-color/m-p/966546#M376155</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-05-15T09:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: ODS Excel- conditional sheet tab color</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ODS-Excel-conditional-sheet-tab-color/m-p/966551#M376156</link>
      <description>&lt;P&gt;It is perfect,&lt;/P&gt;
&lt;P&gt;only one note--- the first query is not 100% correct by my opinion.&lt;/P&gt;
&lt;P&gt;Need to check first if there is any row with value greater then 30,000 and then based on this value convert it to red or green.&lt;/P&gt;
&lt;P&gt;In your code I think that it check every row and in bottom line the color based on last row only&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
  
proc sql  noprint;
select case when a.max_invoice&amp;gt;30000 then 'red ' else 'green' end  as Ind_max_invoice_Gt_30K  into :Ind_max_invoice_Gt_30K
From 
(select max(invoice) as max_invoice
from sashelp.cars
where Make="Honda") as a
;
quit;
%put Ind_max_invoice_Gt_30K=&amp;amp;Ind_max_invoice_Gt_30K;

 
ods excel file="c:\temp\Honda_Report.xlsx" 
options  (sheet_name='Honda'
embedded_titles='yes' 
embedded_footnotes='yes'
sheet_interval="proc" 
gridlines = 'yes'
zoom='50'
tab_color="&amp;amp;Ind_max_invoice_Gt_30K."  /*Change TAB Color based on macro var  Ind_max_invoice_Gt_30K  :  if =1 then Red , else Green*/
);
title 'Honda_Report';
proc report data=sashelp.cars contents="Honda Cars" nowd;
	  where Make="Honda";
	  column ("Car" make model) ("Cost" msrp invoice) 
           ("Fuel Efficiency" mpg_city mpg_highway);  
run;
ods excel  close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 10:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ODS-Excel-conditional-sheet-tab-color/m-p/966551#M376156</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-05-15T10:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: ODS Excel- conditional sheet tab color</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ODS-Excel-conditional-sheet-tab-color/m-p/966652#M376193</link>
      <description>&lt;P&gt;Nope.&lt;BR /&gt;Here I used summary function "max(invoice)" which is applied to all the data ,not just based on the last row , it is based on ALL the rows.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;a.k.a&amp;nbsp; max() would get only &lt;FONT color="#FF0000"&gt;ONE&lt;/FONT&gt; value ,not N values for all the rows.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;If you don't believe it, you could test it on your own.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 May 2025 01:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ODS-Excel-conditional-sheet-tab-color/m-p/966652#M376193</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-05-16T01:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: ODS Excel- conditional sheet tab color</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ODS-Excel-conditional-sheet-tab-color/m-p/966670#M376199</link>
      <description>&lt;P&gt;great, thank you .&lt;/P&gt;
&lt;P&gt;So this code-&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;proc sql  noprint;
select case when a.max_invoice&amp;gt;30000 then 'red ' else 'green' end  as Ind_max_invoice_Gt_30K  into :Ind_max_invoice_Gt_30K
From 
(select max(invoice) as max_invoice
from sashelp.cars
where Make="Honda") as a
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is equivalent to this code-&lt;/P&gt;
&lt;PRE&gt;proc sql  noprint;
select case when max(invoice)&amp;gt;30000 then 'red ' else 'green' end  as Ind_max_invoice_Gt_30K  into :Ind_max_invoice_Gt_30K
from sashelp.cars
where Make="Honda"
;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 May 2025 10:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ODS-Excel-conditional-sheet-tab-color/m-p/966670#M376199</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-05-16T10:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: ODS Excel- conditional sheet tab color</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ODS-Excel-conditional-sheet-tab-color/m-p/966748#M376211</link>
      <description>Yes.</description>
      <pubDate>Sat, 17 May 2025 01:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ODS-Excel-conditional-sheet-tab-color/m-p/966748#M376211</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-05-17T01:24:13Z</dc:date>
    </item>
  </channel>
</rss>

