<?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: aggregate a computed column in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-report-aggregate-a-computed-column/m-p/41133#M10623</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a proc report:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc report data=mydata;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; column myfield1 myfield2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; define myfield1 / group;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; define myfield2 / computed;&lt;/P&gt;&lt;P&gt;[..]&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where the values of myfield2 are either 1 oder 0.&lt;/P&gt;&lt;P&gt;I'd like to have now a myfield3 which ist the aggregated value of myfield2. That means, myfield3 should have the values 1 , 2, 3, 4, etc. and 1 is added as soosn as myfield2 is 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is like retain in the data step. But when I use retain in a compute statement for myfield3 I get an error implicating that I can't use retain here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately I cannot use a data step with retain before the proc report (which is much more complicated than the simle example here) to solve the problem as myfield2 can only be computed in the proc report.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any way to do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best wishes&lt;/P&gt;&lt;P&gt;Eva&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 30 Jan 2012 14:16:17 GMT</pubDate>
    <dc:creator>Eva</dc:creator>
    <dc:date>2012-01-30T14:16:17Z</dc:date>
    <item>
      <title>proc report: aggregate a computed column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-report-aggregate-a-computed-column/m-p/41133#M10623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a proc report:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc report data=mydata;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; column myfield1 myfield2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; define myfield1 / group;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; define myfield2 / computed;&lt;/P&gt;&lt;P&gt;[..]&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where the values of myfield2 are either 1 oder 0.&lt;/P&gt;&lt;P&gt;I'd like to have now a myfield3 which ist the aggregated value of myfield2. That means, myfield3 should have the values 1 , 2, 3, 4, etc. and 1 is added as soosn as myfield2 is 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is like retain in the data step. But when I use retain in a compute statement for myfield3 I get an error implicating that I can't use retain here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately I cannot use a data step with retain before the proc report (which is much more complicated than the simle example here) to solve the problem as myfield2 can only be computed in the proc report.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any way to do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best wishes&lt;/P&gt;&lt;P&gt;Eva&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jan 2012 14:16:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-report-aggregate-a-computed-column/m-p/41133#M10623</guid>
      <dc:creator>Eva</dc:creator>
      <dc:date>2012-01-30T14:16:17Z</dc:date>
    </item>
    <item>
      <title>proc report: aggregate a computed column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-report-aggregate-a-computed-column/m-p/41134#M10624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Eva,&lt;/P&gt;&lt;P&gt;Since reported items are not retained, you would need a non-report temporary variable to retain the value: The following code is just to show how to retain a variable of interest.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc report data=sashelp.class nowd headline out=tst1;&lt;/P&gt;&lt;P&gt;column sex age height weight age=no col_a;&lt;/P&gt;&lt;P&gt;define sex / group;&lt;/P&gt;&lt;P&gt;define height / analysis mean;&lt;/P&gt;&lt;P&gt;define no / analysis n "Count"format=comma12.0;&lt;/P&gt;&lt;P&gt;compute col_a;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp1+height.mean*no;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; col_a=temp1;&lt;/P&gt;&lt;P&gt;endcomp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Say You want to retain col_a, but you can't do it directly by using retain or summary function, however, if you introduce a new Non-reported variable 'temp1', then you get your workaround.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jan 2012 14:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-report-aggregate-a-computed-column/m-p/41134#M10624</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-01-30T14:52:36Z</dc:date>
    </item>
    <item>
      <title>proc report: aggregate a computed column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-report-aggregate-a-computed-column/m-p/41135#M10625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Dear Haikuo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanx for the answer and the general rule that report items cannot be retained but temporary variables. That's a godd rule to keep in mind.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So when I run the example I see that the temporary variable temp1 was initialized with 0. I then thought about initializing it with another value and this is what works:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;﻿compute before;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp1 = 100;&lt;/P&gt;&lt;P&gt;endcomp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best wishes,&lt;/P&gt;&lt;P&gt;Eva&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Feb 2012 08:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-report-aggregate-a-computed-column/m-p/41135#M10625</guid>
      <dc:creator>Eva</dc:creator>
      <dc:date>2012-02-01T08:48:02Z</dc:date>
    </item>
  </channel>
</rss>

