<?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 compute block for all columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779471#M248253</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a report that runs with the potential of having a different amount of columns depending on the raw data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using a proc report compute block to try and highlight specific cells. Through testing, i have got the code to behave the way I want whilst setting the column name manually as a macro variable but I'd like the compute block to apply all columns regardless of the number of columns or their names etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What's the best way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the reporting step with the macro variable &amp;amp;COLUMN set to an individual column name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC REPORT 
DATA=OUTPUT_%sysfunc(trim(&amp;amp;BATTERY))_%sysfunc(trim(&amp;amp;REPORT_TXT))  NOWD NOCENTER
	style(column)=[width=12mm]
	STYLE(header)=[background=skyblue];

	where date &amp;lt;&amp;gt; '.'d;

    COLUMNS ("Coke Ovens Emission Survey Results Table.    Battery:  &amp;amp;Battery   Location:  &amp;amp;REPORT_TXT" &amp;amp;sorted_cols);
	DEFINE DATE / order style=[cellwidth=20mm];

	COMPUTE &amp;amp;COLUMN;
		if SUBSTR(&amp;amp;COLUMN,3,1) = '' and &amp;amp;COLUMN ^= '' then do; /*Bookable emissions only*/
     		call define(_col_, "style", "style=[backgroundcolor=orange]");
		end;
	endcomp;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Zac&lt;/P&gt;</description>
    <pubDate>Wed, 10 Nov 2021 00:30:25 GMT</pubDate>
    <dc:creator>ZacLopresti</dc:creator>
    <dc:date>2021-11-10T00:30:25Z</dc:date>
    <item>
      <title>Proc report compute block for all columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779471#M248253</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a report that runs with the potential of having a different amount of columns depending on the raw data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using a proc report compute block to try and highlight specific cells. Through testing, i have got the code to behave the way I want whilst setting the column name manually as a macro variable but I'd like the compute block to apply all columns regardless of the number of columns or their names etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What's the best way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the reporting step with the macro variable &amp;amp;COLUMN set to an individual column name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC REPORT 
DATA=OUTPUT_%sysfunc(trim(&amp;amp;BATTERY))_%sysfunc(trim(&amp;amp;REPORT_TXT))  NOWD NOCENTER
	style(column)=[width=12mm]
	STYLE(header)=[background=skyblue];

	where date &amp;lt;&amp;gt; '.'d;

    COLUMNS ("Coke Ovens Emission Survey Results Table.    Battery:  &amp;amp;Battery   Location:  &amp;amp;REPORT_TXT" &amp;amp;sorted_cols);
	DEFINE DATE / order style=[cellwidth=20mm];

	COMPUTE &amp;amp;COLUMN;
		if SUBSTR(&amp;amp;COLUMN,3,1) = '' and &amp;amp;COLUMN ^= '' then do; /*Bookable emissions only*/
     		call define(_col_, "style", "style=[backgroundcolor=orange]");
		end;
	endcomp;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Zac&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 00:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779471#M248253</guid>
      <dc:creator>ZacLopresti</dc:creator>
      <dc:date>2021-11-10T00:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc report compute block for all columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779505#M248267</link>
      <description>&lt;P&gt;Can you post an excerpt of the data and explain why you have a different number of variables? It seems as the data should be transposed, so that "across" could be used.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 06:08:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779505#M248267</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-11-10T06:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: Proc report compute block for all columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779600#M248325</link>
      <description>&lt;P&gt;Some data&lt;/P&gt;
&lt;P&gt;Code without macro variables using that data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Stuff like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;if SUBSTR(&amp;amp;COLUMN,3,1) = '' and &amp;amp;COLUMN ^= ''&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;might be an indication that the data could use some modification prior to the report or possibly even a format could be used instead of logic to assign highlight colors &lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 16:35:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779600#M248325</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-11-10T16:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: Proc report compute block for all columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779710#M248382</link>
      <description>&lt;P&gt;Thanks for the response!&lt;/P&gt;&lt;P&gt;I've added a sample and a screenshot below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The change in the number of variables is a result of there not being data present for every single oven within the reporting period. As a result, ovens without text in the cell for any of the reporting period dates don't need to be displayed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What do you mean by across?&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="ZacLopresti_0-1636610249331.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65581i4E71B108DA98CD3D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ZacLopresti_0-1636610249331.png" alt="ZacLopresti_0-1636610249331.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data work.SAMPLE;
	infile datalines dlm=',';
	input DATE date9. OVEN_0051 $ OVEN_0052 $ OVEN_0054 $;
datalines;
12OCT2021, , ,TT(F)
13OCT2021,CD(N), ,BL
14OCT2021, ,TT, 
;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Zac&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 05:58:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779710#M248382</guid>
      <dc:creator>ZacLopresti</dc:creator>
      <dc:date>2021-11-11T05:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc report compute block for all columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779711#M248383</link>
      <description>Ill look into that thanks.&lt;BR /&gt;Do you have any good examples?</description>
      <pubDate>Thu, 11 Nov 2021 06:00:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779711#M248383</guid>
      <dc:creator>ZacLopresti</dc:creator>
      <dc:date>2021-11-11T06:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: Proc report compute block for all columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779714#M248385</link>
      <description>&lt;P&gt;I would start by transposing the data, so that you have one variable "oven" containing the text on the right side of the underscore and another variable for the value. Yes, this will make you dataset less human-readable, but maybe easier to process: you could use a where-statement to select all values that are "bookable emissions". If you have to list the ovens horizontally, the table will still have many, many empty cells.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I still have trouble figuring out how the report should look like, so this suggestion may lead to more problems.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 06:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779714#M248385</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-11-11T06:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc report compute block for all columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779729#M248389</link>
      <description>&lt;P&gt;After making your sample code work, here's an example of using a long dataset in PROC REPORT with ACROSS:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.SAMPLE;
infile datalines dlm=',' dsd truncover;
input DATE :date9. OVEN_0051 $ OVEN_0052 $ OVEN_0054 $;
format date yymmdd10.;
datalines;
12OCT2021, , ,TT(F)
13OCT2021,CD(N), ,BL
14OCT2021, ,TT, 
;

proc transpose
  data=sample
  out=long1 (
    rename=(col1=emission)
    where=(emission ne "")
  )
;
by date;
var oven:;
run;

data long2;
set long1;
length oven $4;
oven = scan(_name_,2,"_");
drop _name_;
run;

proc report data=long2;
column date emission,oven n;
define date / "Oven" group;
define emission / "" display;
define oven / "" across;
define n / noprint;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And from the same dataset, it is now very easy to create a pivoted report:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=long2;
column oven emission,date n;
define oven / "Date" group;
define emission / "" display;
define date / "" across;
define n / noprint;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Similar is true for all kinds of analysis. Always keep data out of structure.&lt;/P&gt;
&lt;P&gt;Maxim 19: Long Beats Wide.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 08:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/779729#M248389</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-11T08:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc report compute block for all columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/780875#M248861</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;
&lt;P&gt;I think I understand all that you're saying and the code makes sense.&lt;/P&gt;
&lt;P&gt;In this approach at which stage would you try to highlight the cells?&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 21:00:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-report-compute-block-for-all-columns/m-p/780875#M248861</guid>
      <dc:creator>ZacLopresti</dc:creator>
      <dc:date>2021-11-17T21:00:26Z</dc:date>
    </item>
  </channel>
</rss>

