<?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: Using ARRAYs in a PROC REPORT COMPUTE block in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925679#M364257</link>
    <description>&lt;P&gt;Paige,&lt;/P&gt;
&lt;P&gt;I think it is very hard to do this .&amp;nbsp; Maybe&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;knew how to do it ?&lt;/P&gt;
&lt;P&gt;Here is another simple way to do it .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.example;
  infile datalines dsd truncover;
  input date state:$4. rate:32.;
  if rate&amp;gt;0.1 then _rate=cats('(*ESC*){style [background=lightmoderatered]',put(rate,percent8.2),'}');
    else _rate=put(rate,percent8.2);
datalines4;
2013,FL,0.1355932203
2013,MA,0.0294117647
2013,NY,0.0977443609
2014,FL,0.0487804878
2014,MA,0.0606060606
2014,NY,0.0614035088
2015,FL,0.0833333333
2015,MA,0.0487804878
2015,NY,0.0625
2016,FL,0.071942446
2016,MA,0.1020408163
2016,NY,0.0756302521
2017,FL,0.0508474576
2017,MA,0.0277777778
2017,NY,0.0714285714
2018,FL,0.0112359551
2018,MA,0
2018,NY,0.0561797753
2019,FL,0.0438596491
2019,MA,0.0689655172
2019,NY,0.0784313725
2020,FL,0.0347222222
2020,MA,0
2020,NY,0.0333333333
2021,FL,0.0105263158
2021,MA,0
2021,NY,0.0178571429
2022,FL,0.0188679245
2022,MA,0.0833333333
2022,NY,0
2023,FL,0
2023,MA,0
2023,NY,0.0454545455
2024,FL,0
2024,MA,0
2024,NY,0
;;;;
ods rtf file='c:\temp\temp.rtf' style=journal;
proc report data=example nowd;
    columns state date,_rate ;
    define state/group;
    define date/across;
    define _rate/group;
run;
ods rtf close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 25 Apr 2024 01:51:47 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-04-25T01:51:47Z</dc:date>
    <item>
      <title>Using ARRAYs in a PROC REPORT COMPUTE block</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925546#M364223</link>
      <description>&lt;P&gt;Way back in 2023,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;produced &lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-use-proc-report-with-same-compute-block-for-many/m-p/873801#M345225" target="_self"&gt;this example&lt;/A&gt; of using an ARRAY in a PROC REPORT compute&amp;nbsp; block. In that example, there was no ACROSS variable. My question today is can this be done with an ACROSS variable, where the columns names are _Cn_??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example: here I have DATE as an ACROSS variable, and in the COMPUTE block I have created two lines that change the background color if the value of the variable is &amp;gt;0.1. But I had to type those lines myself, and there are many more that I haven't typed. I am wondering if an ARRAY can work here which covers all columns of the ACROSS variable. If so, how? (Also, I'm sure I can write a macro to do this, but the question is specifically can an ARRAY be used and how?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.example;
  infile datalines dsd truncover;
  input date state:$4. rate:32.;
datalines4;
2013,FL,0.1355932203
2013,MA,0.0294117647
2013,NY,0.0977443609
2014,FL,0.0487804878
2014,MA,0.0606060606
2014,NY,0.0614035088
2015,FL,0.0833333333
2015,MA,0.0487804878
2015,NY,0.0625
2016,FL,0.071942446
2016,MA,0.1020408163
2016,NY,0.0756302521
2017,FL,0.0508474576
2017,MA,0.0277777778
2017,NY,0.0714285714
2018,FL,0.0112359551
2018,MA,0
2018,NY,0.0561797753
2019,FL,0.0438596491
2019,MA,0.0689655172
2019,NY,0.0784313725
2020,FL,0.0347222222
2020,MA,0
2020,NY,0.0333333333
2021,FL,0.0105263158
2021,MA,0
2021,NY,0.0178571429
2022,FL,0.0188679245
2022,MA,0.0833333333
2022,NY,0
2023,FL,0
2023,MA,0
2023,NY,0.0454545455
2024,FL,0
2024,MA,0
2024,NY,0
;;;;

proc report data=example;
    columns state date,rate dummy;
    define state/group;
    define date/across;
    define rate/mean format=percent8.2;
    define dummy/noprint;
    compute dummy;
        if _c2_&amp;gt;0.1 then call define ("_c2_",'style','style={background=lightmoderatered}');
        if _c3_&amp;gt;0.1 then call define ("_c3_",'style','style={background=lightmoderatered}');
    endcompute;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 12:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925546#M364223</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-24T12:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using ARRAYs in a PROC REPORT COMPUTE block</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925567#M364225</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Seems to work if you type the list of variable names &lt;FONT face="courier new,courier"&gt;_c2_ _c3_&lt;/FONT&gt; ... in the ARRAY statement or create it, e.g., with a little macro:&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;%macro _c(n);
%do n=2 %to &amp;amp;n; _c&amp;amp;n._ %end;
%mend _c;&lt;/STRONG&gt;

&lt;FONT color="#999999"&gt;proc report data=example;
    columns state date,rate dummy;
    define state/group;
    define date/across;
    define rate/mean format=percent8.2;
    define dummy/noprint;
    compute dummy;
&lt;STRONG&gt;      &lt;FONT color="#000000"&gt;array r[*] %_c(99);
      do i=1 to dim(r);&lt;/FONT&gt;&lt;/STRONG&gt;
        if &lt;FONT color="#000000"&gt;&lt;STRONG&gt;r[i]&lt;/STRONG&gt;&lt;/FONT&gt;&amp;gt;0.1 then call define (&lt;FONT color="#000000"&gt;&lt;STRONG&gt;vname(r[i])&lt;/STRONG&gt;&lt;/FONT&gt;,'style','style={background=lightmoderatered}');
      &lt;STRONG&gt;&lt;FONT color="#000000"&gt;end;&lt;/FONT&gt;&lt;/STRONG&gt;
    endcomp;
run;&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Apr 2024 14:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925567#M364225</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-04-24T14:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using ARRAYs in a PROC REPORT COMPUTE block</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925571#M364227</link>
      <description>&lt;P&gt;I had not considered a "hybrid" of small macro plus ARRAYs. Thanks, I'm sure that will work. If anyone else has suggestions about a different approach, please let me know.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 14:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925571#M364227</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-24T14:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using ARRAYs in a PROC REPORT COMPUTE block</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925592#M364237</link>
      <description>&lt;P&gt;Don't need to use macro to generate the list of column references.&amp;nbsp; For example you could use PROC SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
 select cats('_c',1+monotonic(),'_') into :list separated by ' '
 from (select distinct date from example);
quit;

proc report data=example;
    columns state rate,date dummy;
    define state/group;
    define date/across;
    define rate/mean format=percent8.2 ' ';
    define dummy/noprint;
    compute dummy;
      array r[*]  &amp;amp;list ;
      do i=1 to dim(r);
        if r[i]&amp;gt;0.1 then call define (vname(r[i]),'style','style={background=lightmoderatered}');
      end;
    endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the across variable is not at position 2 then change the offset in the SQL code from 1 to the appropriate number.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1713975038623.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95825iE05D2C6830F39D57/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1713975038623.png" alt="Tom_0-1713975038623.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 16:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925592#M364237</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-24T16:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using ARRAYs in a PROC REPORT COMPUTE block</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925663#M364254</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A very nice use case for the undocumented "monotonic" function in PROC SQL.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 20:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925663#M364254</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-04-24T20:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using ARRAYs in a PROC REPORT COMPUTE block</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925679#M364257</link>
      <description>&lt;P&gt;Paige,&lt;/P&gt;
&lt;P&gt;I think it is very hard to do this .&amp;nbsp; Maybe&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;knew how to do it ?&lt;/P&gt;
&lt;P&gt;Here is another simple way to do it .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.example;
  infile datalines dsd truncover;
  input date state:$4. rate:32.;
  if rate&amp;gt;0.1 then _rate=cats('(*ESC*){style [background=lightmoderatered]',put(rate,percent8.2),'}');
    else _rate=put(rate,percent8.2);
datalines4;
2013,FL,0.1355932203
2013,MA,0.0294117647
2013,NY,0.0977443609
2014,FL,0.0487804878
2014,MA,0.0606060606
2014,NY,0.0614035088
2015,FL,0.0833333333
2015,MA,0.0487804878
2015,NY,0.0625
2016,FL,0.071942446
2016,MA,0.1020408163
2016,NY,0.0756302521
2017,FL,0.0508474576
2017,MA,0.0277777778
2017,NY,0.0714285714
2018,FL,0.0112359551
2018,MA,0
2018,NY,0.0561797753
2019,FL,0.0438596491
2019,MA,0.0689655172
2019,NY,0.0784313725
2020,FL,0.0347222222
2020,MA,0
2020,NY,0.0333333333
2021,FL,0.0105263158
2021,MA,0
2021,NY,0.0178571429
2022,FL,0.0188679245
2022,MA,0.0833333333
2022,NY,0
2023,FL,0
2023,MA,0
2023,NY,0.0454545455
2024,FL,0
2024,MA,0
2024,NY,0
;;;;
ods rtf file='c:\temp\temp.rtf' style=journal;
proc report data=example nowd;
    columns state date,_rate ;
    define state/group;
    define date/across;
    define _rate/group;
run;
ods rtf close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 01:51:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925679#M364257</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-04-25T01:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using ARRAYs in a PROC REPORT COMPUTE block</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925851#M364317</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Well, if I couldn't use a FORMAT, which would avoid the need for using the COMPUTE block:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1714067704877.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95886i846CB7038055C6B5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1714067704877.png" alt="Cynthia_sas_0-1714067704877.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I'd probably use some kind of macro program to build the COMPUTE block. I tend to avoid the use of monotonic since 1) it is undocumented and 2) there was a TS note that is might produce undesirable results, so I'd probably just use a different procedure to determine how many years there were and then use that value to generate the ARRAY/COMPUTE block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; But for a simple example like this, my choice would be a user-defined format for the background.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 17:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925851#M364317</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2024-04-25T17:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using ARRAYs in a PROC REPORT COMPUTE block</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925858#M364321</link>
      <description>&lt;P&gt;Thanks, all! Very helpful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Side note: to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp; Your comments about MONOTONIC() agree with my opinions about not using it, as I don't really grasp all the situations where trouble could arise. Nevertheless, I attended a talk by someone from SAS (I don't remember the person's name) on the subject of when to use a DATA step and when to use SQL, and in that talk, the use of MONOTONIC() was actually recommended. Seems like two different SAS employees are on opposite sides of this issue, and I would have thought that there would be some agreement at least among SAS employees about not using MONOTONIC().&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 18:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925858#M364321</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-25T18:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using ARRAYs in a PROC REPORT COMPUTE block</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925872#M364330</link>
      <description>Hi, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; -- I'm sure that Monotonic does work in some usage scenarios. However, as someone who used to work with attorneys, producing reports for discovery and testimony, I could only use supported features of the software. So, THIS note: &lt;A href="https://support.sas.com/kb/15/138.html" target="_blank"&gt;https://support.sas.com/kb/15/138.html&lt;/A&gt; is the reason I do not personally use monotonic in any of my code. I'm sure it's fine if others want to try it. I just don't want to find what undesirable means when it's my code and results under the magnifying glass.&lt;BR /&gt;Cynthia</description>
      <pubDate>Thu, 25 Apr 2024 19:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925872#M364330</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2024-04-25T19:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using ARRAYs in a PROC REPORT COMPUTE block</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925977#M364371</link>
      <description>&lt;P&gt;I agree, I won't use it either, since I don't understand what situations it doesn't work, and since it is unsupported it might not work in the next upgrade of SAS. I was shocked when listening to the presentation that no warnings about the function is unsupported were given.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 09:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-ARRAYs-in-a-PROC-REPORT-COMPUTE-block/m-p/925977#M364371</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-26T09:36:49Z</dc:date>
    </item>
  </channel>
</rss>

