<?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: PROC PRINT: having observations grouped visually? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606490#M176115</link>
    <description>&lt;P&gt;Perhaps a different procedure.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;proc report data=sashelp.cars (obs=100);
   columns make model type origin drivetrain;
   define make / group;
run;&lt;/PRE&gt;</description>
    <pubDate>Fri, 22 Nov 2019 15:30:49 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-11-22T15:30:49Z</dc:date>
    <item>
      <title>PROC PRINT: having observations grouped visually?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606469#M176108</link>
      <description>&lt;P&gt;I was wondering if there is a way to use colors or something to make different groups more distinguishable in PROC PRINT.&amp;nbsp;For example, the following code shows the first 100 observations, which can be grouped by Make.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data= sashelp.cars (obs= 100); run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first 7 have Make of "Acura" and the next 20 have Make of "Audi". Can these two groups have different colors so that they are easily distinguishable from each other? The next group is "BMW". I think "BMW" observations may have the same color as "Acura" because they are displayed next to each other.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I usually deal with panel data sets, so visually grouping my data when using PROC PRINT would make it a lot easier to inspect.&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, 22 Nov 2019 14:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606469#M176108</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-11-22T14:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: PROC PRINT: having observations grouped visually?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606473#M176110</link>
      <description>&lt;P&gt;PROC PRINT has limited ability to change colors, background colors, fonts, &lt;EM&gt;etc&lt;/EM&gt;. PROC PRINT does allow the BY statement to separate groups of observations, although I think the colors would not change from one BY group to another.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC REPORT will let you assign different colors to different groups of observations.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2019 14:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606473#M176110</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-22T14:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: PROC PRINT: having observations grouped visually?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606476#M176111</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; What color do you want to change? Background? Foreground? And, do you want to change just the cell with the value Audi or Acura? Or do you want to change the whole row? If you want to change the whole row, based on the value of the Make, then you'll need to switch to PROC REPORT instead of PROC PRINT. Look at some of the examples in this paper: &lt;A href="http://support.sas.com/resources/papers/proceedings13/366-2013.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings13/366-2013.pdf&lt;/A&gt; In particular, look at pages 9 and 10 if all you want to do is change the color of the Make cell. The paper has an example of coloring the Name cell.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; But if you want to color a whole row, then look at pages 12-14 which show coloring a whole ROW for the name='Alice'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2019 14:46:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606476#M176111</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2019-11-22T14:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: PROC PRINT: having observations grouped visually?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606490#M176115</link>
      <description>&lt;P&gt;Perhaps a different procedure.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;proc report data=sashelp.cars (obs=100);
   columns make model type origin drivetrain;
   define make / group;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Nov 2019 15:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606490#M176115</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-22T15:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: PROC PRINT: having observations grouped visually?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606524#M176130</link>
      <description>&lt;P&gt;Thanks! Do you suggest using PROC FORMAT and PROC REPORT together? That looks like what I'm looking for. Yes, I would like to have different colors for the whole rows of a group.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, a tricky issue is that my panel data set usually contains more than 1000 groups, so I don't think I can assign different colors to each of them using proc format. Rather, I would like to use TWO colors to make adjoining groups look distinguishable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, Let's say that there are four groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Group 1: YELLOW&lt;/P&gt;
&lt;P&gt;Group 2: GREY&lt;/P&gt;
&lt;P&gt;Group 3: YELLOW&lt;/P&gt;
&lt;P&gt;Group 4: GREY&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have any suggestion for this? Sorry for not having made my question clearer in the beginning.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2019 17:58:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606524#M176130</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-11-22T17:58:18Z</dc:date>
    </item>
    <item>
      <title>Re: PROC PRINT: having observations grouped visually?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606540#M176140</link>
      <description>&lt;P&gt;You can use the ID statement with the BY statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data= sashelp.cars (obs=10); 
  by make; 
  id make;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 468px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34182iB007A6A9568AA7D4/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2019 18:33:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606540#M176140</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-22T18:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: PROC PRINT: having observations grouped visually?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606555#M176144</link>
      <description>&lt;P&gt;HI:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; I'd use a variation on that program in the paper because you can create a "counter" variable to identify the unique groups. When the counter variable is even, use one color, when the counter variable is odd use a different color:&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="alternate_colors.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34184iFDB0D4CAB8270B61/image-size/large?v=v2&amp;amp;px=999" role="button" title="alternate_colors.png" alt="alternate_colors.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I used green and gray in honor of the nice "greenbar" paper that I used in the old mainframe printer days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In order to create the counter variable (CNTMAKE), I needed for MAKE to be an ORDER usage (not the default of DISPLAY). This would have meant that MAKE would only appear on the first row of the group (such as shown in the ID example for PROC PRINT). But to have MAKE appear on every row, I created a COMPUTED item called DISPMAKE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the COMPUTE block for MAKE, I have the CALL DEFINE statement, but it needs some information. I have to find out whether this group is even or odd, based on CNTMAKE. I use the MOD function to do that. MOD divides a number and provides the remainder as a result. In this case, if the CNTMAKE number, divided by 2 is 0, that means the number is even and the row will get the green color (specified as a hex HTML color code). Otherwise, if the number is not even, it is odd, and the row will get the gray color.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps explain the case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2019 19:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606555#M176144</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2019-11-22T19:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: PROC PRINT: having observations grouped visually?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606573#M176147</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for your awesome explanation! Following your suggestion, I made some modifications. Both work very well for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc report data=sashelp.cars(obs=100) nowd;
	column make type model origin msrp invoice;
   compute type ;
		if make^= lag (make) then count+1;
      if mod(count,2) then do;
         call define(_row_, "style", "style=[background=lightyellow]");
      end;
   endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm not so familar to PROC REPORT, and I would like to mimic PROC PRINT using PROC REPORT as you already know. Now I'm wondering if I really have to define all columns in PROC REPORT. If I just want to mimic PROC REPORT, do you think my code is fine? Or do I take any risk?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2019 21:02:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606573#M176147</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-11-22T21:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC PRINT: having observations grouped visually?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606578#M176152</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is MAKE in "COMPUTE BEFORE MAKE" just a random choice? Thanks again.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2019 21:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606578#M176152</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-11-22T21:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: PROC PRINT: having observations grouped visually?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606603#M176170</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279507"&gt;@braam&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is MAKE in "COMPUTE BEFORE MAKE" just a random choice? Thanks again.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;MAKE is your variable, so not at all random. Proc Report builds reports from left to right so to assign properties to the whole row you want to test the "left most" item to set a property for elements including that left most column.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2019 23:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606603#M176170</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-22T23:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: PROC PRINT: having observations grouped visually?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606606#M176171</link>
      <description>Hi:&lt;BR /&gt;  I prefer NOT to use LAG in PROC REPORT. The COMPUTE BEFORE MAKE allows me to use PROC REPORTs internal "break" variable to keep track of the first of the group. Your code is less efficient because you are running the function on EVERY row. I am only executing the statements in the COMPUTE block for BEFORE 1 time for every unique group. You don't need your test on EVERY row because there's only 1 time in the group when the test will be true -- but still you are doing the test on EVERY row.&lt;BR /&gt;&lt;BR /&gt;  And, since I know that PROC REPORT does not have a PDV like the DATA step, I tend to avoid functions that rely on "look-back" or "look-ahead".&lt;BR /&gt;&lt;BR /&gt;Cynthia</description>
      <pubDate>Fri, 22 Nov 2019 23:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-PRINT-having-observations-grouped-visually/m-p/606606#M176171</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2019-11-22T23:36:47Z</dc:date>
    </item>
  </channel>
</rss>

