<?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: computing arrays in compute blocks in proc report? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425327#M68266</link>
    <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; If you're just listing them in the COLUMN statement, I'd be tempted to use PROC FORMAT. Something like this -- since you didn't supply data, I made fake data with SASHELP.CLASS -- only 4 extra vars:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testit;
  set sashelp.class;
  col1 = age+height;
  col2 = age+height+weight;
  col3 = height+weight;
  col4 = age*age;
  if sex = 'M' and age = 13 then col3 = .;
  else if sex = 'F' and age = 14 then col4 = .;
run;
  
proc format;
  value bck_val .='white'
                other='lightred';
  value for_val .=white
                other='black';
run;
  
proc report data=testit;
  column name age sex height weight col1 col2 col3 col4 ;
  define name / order;
  define age / display;
  define sex / display;
  define height / display;
  define weight / display;
  define col1 / display; 
  define col2 / display; 
  define col3 / display style(column)={background=bck_val. color=for_val.}; 
  define col4 / display style(column)={background=bck_val. color=for_val.};
 run;
 

  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and that code produces this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="use_format_report.png" style="width: 428px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17665i3DCA7F047EE80324/image-size/large?v=v2&amp;amp;px=999" role="button" title="use_format_report.png" alt="use_format_report.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;with only col3 and col4 highlighted based on the user-defined format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Jan 2018 18:46:43 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2018-01-05T18:46:43Z</dc:date>
    <item>
      <title>computing arrays in compute blocks in proc report?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425310#M68263</link>
      <description>&lt;P&gt;Happy Friday all!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure how to get started on this one-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have a proc report with essentially a facility name and then col1-colx;&lt;/P&gt;
&lt;P&gt;Generally columns col1-col4 are always populated with data so I am only concerned with col5-colx.&lt;/P&gt;
&lt;P&gt;Colx is dynamic and may change weekly from 10-20 depending.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in a compute block I want to do:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;compute ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if col[i]=' ' then call define(_COL_,'style','style={background=white color=white}');&lt;BR /&gt;if col[i]^=' ' then call define(_COL_,'style','style={background=red color=black}');&lt;/P&gt;
&lt;P&gt;endcomp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so that all the col5-colx will be blank if null and red if there is a value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't span the data per se given the way the data is structured without rewriting large parts of it-otherwise I would do that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I can write a macro to contend with this per se but seeing if there is a simpler solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TIA-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lawrence&lt;/P&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 17:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425310#M68263</guid>
      <dc:creator>LB</dc:creator>
      <dc:date>2018-01-05T17:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: computing arrays in compute blocks in proc report?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425314#M68264</link>
      <description>Hi:&lt;BR /&gt;  You would either need a separate compute block for each col value or you would need to have a dummy variable at the end of the report row, that you let you address each of the previous columns on the row. &lt;BR /&gt;&lt;BR /&gt;Critical to coding this will be understanding whether you list col1-colx on the column statement or whether you have them under an ACROSS item, that will make a difference in how you declare the array members.&lt;BR /&gt;&lt;BR /&gt;cynthia</description>
      <pubDate>Fri, 05 Jan 2018 18:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425314#M68264</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-01-05T18:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: computing arrays in compute blocks in proc report?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425317#M68265</link>
      <description>&lt;P&gt;Hi Cynthia-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They are listed as&amp;nbsp;&lt;SPAN&gt;col1-colx on the column statement.&amp;nbsp; I'm trying to avoid computing each column5-colx&amp;nbsp; as colx is variable week to week-&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am trying to make use of this&amp;nbsp; link-&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="http://support.sas.com/kb/43/765.html&amp;nbsp;" target="_blank"&gt;http://support.sas.com/kb/43/765.html&amp;nbsp;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;but still having some challenges&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;amp;mstoolo- is equal to col1-colx&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Below I am just trying to do it for for 4 columns-Once I figure it out I can insert macro vars.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;proc report data=stoolie_tg;&lt;BR /&gt;columns facid ("Numbers of stools*^" &amp;amp;mstoolo) dummy;&lt;BR /&gt;....&lt;BR /&gt;define dummy / computed noprint;&lt;BR /&gt; compute dummy;&lt;BR /&gt; &lt;BR /&gt; array flag(4) stool5 stool6 stool7 stool8;&lt;BR /&gt; do i=1 to dim(flag);&lt;BR /&gt; if flag(i)=' ' then call define(_COL_,'style','style={background=white color=white}');&lt;BR /&gt; if flag(i)^=' ' then call define(_COL_,'style','style={background=salmon color=white}');&lt;BR /&gt; end;&lt;BR /&gt; endcomp;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks again.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Lawrence&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 18:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425317#M68265</guid>
      <dc:creator>LB</dc:creator>
      <dc:date>2018-01-05T18:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: computing arrays in compute blocks in proc report?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425327#M68266</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; If you're just listing them in the COLUMN statement, I'd be tempted to use PROC FORMAT. Something like this -- since you didn't supply data, I made fake data with SASHELP.CLASS -- only 4 extra vars:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testit;
  set sashelp.class;
  col1 = age+height;
  col2 = age+height+weight;
  col3 = height+weight;
  col4 = age*age;
  if sex = 'M' and age = 13 then col3 = .;
  else if sex = 'F' and age = 14 then col4 = .;
run;
  
proc format;
  value bck_val .='white'
                other='lightred';
  value for_val .=white
                other='black';
run;
  
proc report data=testit;
  column name age sex height weight col1 col2 col3 col4 ;
  define name / order;
  define age / display;
  define sex / display;
  define height / display;
  define weight / display;
  define col1 / display; 
  define col2 / display; 
  define col3 / display style(column)={background=bck_val. color=for_val.}; 
  define col4 / display style(column)={background=bck_val. color=for_val.};
 run;
 

  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and that code produces this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="use_format_report.png" style="width: 428px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17665i3DCA7F047EE80324/image-size/large?v=v2&amp;amp;px=999" role="button" title="use_format_report.png" alt="use_format_report.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;with only col3 and col4 highlighted based on the user-defined format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 18:46:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425327#M68266</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-01-05T18:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: computing arrays in compute blocks in proc report?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425360#M68269</link>
      <description>&lt;P&gt;Cynthia-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-the only issue with the solution is contending with the dynamic nature of how many columns per week-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I am about as stubborn as my dog (beagle) I managed to get the array to work. I just took that link and adapted accordingly-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;arrya &amp;amp; arryb are subsets of&amp;nbsp;&lt;SPAN&gt;&amp;amp;mstoolo&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc report data=stoolie_tg;&lt;BR /&gt;columns facid ("Numbers of stools*^" &amp;amp;mstoolo ) dummy;&lt;BR /&gt;define stool0/style (column)={background=salmon just=center color=black};&lt;BR /&gt;define stool1/style (column)={background=orange just=center color=black};&lt;BR /&gt;define stool2/style (column)={background=#c9df8a just=center color=black};&lt;BR /&gt;define stool3/style (column)={background=#c9df8a just=center color=black};&lt;BR /&gt;define dummy /noprint;&lt;BR /&gt;compute stool4;&lt;BR /&gt;if stool4=' ' then call define(_COL_,'style','style={background=white color=white}');&lt;BR /&gt;if stool4^=' ' then call define(_COL_,'style','style={background=orange color=black}');&lt;BR /&gt;endcomp;&lt;/P&gt;
&lt;P&gt;compute dummy;&lt;BR /&gt; array name(12) $ (&amp;amp;arrya);&lt;BR /&gt; array flag(12) &amp;amp;arryb;&lt;BR /&gt; do i=1 to dim(name);&lt;BR /&gt; call define(name(i),'style','style=[background='||put(flag(i),$bck_val.) ||']');&lt;BR /&gt; end;&lt;BR /&gt; endcomp;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 20:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425360#M68269</guid>
      <dc:creator>LB</dc:creator>
      <dc:date>2018-01-05T20:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: computing arrays in compute blocks in proc report?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425364#M68271</link>
      <description>Ah, well, my tendency would have been to stick with the format and use a macro program to dynamically generate the column statement and the DEFINE statements with the format where I needed it. &lt;BR /&gt;&lt;BR /&gt;But I am glad you made the array work.&lt;BR /&gt;&lt;BR /&gt;cynthia</description>
      <pubDate>Fri, 05 Jan 2018 20:29:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425364#M68271</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-01-05T20:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: computing arrays in compute blocks in proc report?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425369#M68273</link>
      <description>&lt;P&gt;That was my next&amp;nbsp; step if I couldn't.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lawrence&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 20:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/computing-arrays-in-compute-blocks-in-proc-report/m-p/425369#M68273</guid>
      <dc:creator>LB</dc:creator>
      <dc:date>2018-01-05T20:39:33Z</dc:date>
    </item>
  </channel>
</rss>

