<?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: now they tell me in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/now-they-tell-me/m-p/74417#M21586</link>
    <description>Hi:&lt;BR /&gt;
  Here's an example that I had. It shows two things: there are a BUNCH of temporary variables and there's one COMPUTED variable (SILLYVAR). The difference between the two types of variables is outlined in a documentation topic entitled, "".&lt;BR /&gt;
 &lt;BR /&gt;
  This is a very simple example of how certain values were saved into temporary variables in a compute block and then used -- in this case, at the end of the report.  &lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
ods listing close;&lt;BR /&gt;
ods html file='c:\temp\use_temp_var.html' style=sasweb;&lt;BR /&gt;
proc report data=sashelp.class nowd&lt;BR /&gt;
  style(lines)={just=l};&lt;BR /&gt;
  title 'Example: Using Temporary Variables';&lt;BR /&gt;
  title2 'HT12, HT14, HOLD12, HOLD14, AV12, AV14, HOLDALL and HTALL are the temp variables';&lt;BR /&gt;
  title3 'SillyVar is a COMPUTED variable';&lt;BR /&gt;
  column age n  height weight sillyvar;&lt;BR /&gt;
  define age / group;&lt;BR /&gt;
  define n / 'Count';&lt;BR /&gt;
  define height / mean  'Avg Height';&lt;BR /&gt;
  define weight / mean 'Avg Weight';&lt;BR /&gt;
  define sillyvar / computed 'Silly Var';&lt;BR /&gt;
  compute sillyvar;&lt;BR /&gt;
     sillyvar = weight.mean - height.mean;&lt;BR /&gt;
  endcomp;&lt;BR /&gt;
  compute height;&lt;BR /&gt;
    if age = 12 then do; hold12 = n;	ht12 = height.mean; end;&lt;BR /&gt;
    else if age = 14 then do; hold14 = n; ht14 = height.mean; end;&lt;BR /&gt;
    if _break_ = '_RBREAK_' then do; holdall = n; htall = height.mean; end;&lt;BR /&gt;
  endcomp;&lt;BR /&gt;
  rbreak after / summarize;&lt;BR /&gt;
  compute after;&lt;BR /&gt;
    av12 = hold12 / holdall;&lt;BR /&gt;
    av14 = hold14 / holdall;&lt;BR /&gt;
    line 'Average Height for 12 year olds: ' ht12 4.1 ;&lt;BR /&gt;
    line 'This group is ' av12 percent8.2 'of all ages which represents' hold12 2.0 ' divided by ' holdall 2.0; &lt;BR /&gt;
    line ' ';&lt;BR /&gt;
    line 'Average Height for 14 year olds: ' ht14 4.1 ;&lt;BR /&gt;
    line 'This group is ' av14 percent8.2 'of all ages which represents' hold14 2.0 ' divided by ' holdall 2.0; &lt;BR /&gt;
    line ' ';&lt;BR /&gt;
    line 'The overall Average Height is: ' htall 4.1;&lt;BR /&gt;
  endcomp;&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Tue, 06 Oct 2009 16:38:40 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2009-10-06T16:38:40Z</dc:date>
    <item>
      <title>now they tell me</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/now-they-tell-me/m-p/74414#M21583</link>
      <description>after creating a report with proc report I now find out that certain cells should be calculated using the sums from other rows.&lt;BR /&gt;
&lt;BR /&gt;
I have code like &lt;BR /&gt;
compute row_sum; &lt;BR /&gt;
&lt;BR /&gt;
if index(varname,'Percentage') then&lt;BR /&gt;
   row_sum = mean(&lt;BR /&gt;
		%do zz=1 %to &amp;amp;mcount;&lt;BR /&gt;
				 %if %index (&amp;amp;&amp;amp;mname&amp;amp;zz,&amp;amp;&amp;amp;yeardat&amp;amp;yy) %then %do;&lt;BR /&gt;
			%if &amp;amp;&amp;amp;mnum&amp;amp;zz=1 %then %do;&lt;BR /&gt;
				&amp;amp;&amp;amp;mmm&amp;amp;zz&lt;BR /&gt;
			%end;&lt;BR /&gt;
			%if &amp;amp;&amp;amp;mnum&amp;amp;zz&amp;gt;1 %then %do;&lt;BR /&gt;
				, &amp;amp;&amp;amp;mmm&amp;amp;zz &lt;BR /&gt;
			%end;&lt;BR /&gt;
		%end;&lt;BR /&gt;
		%end;&lt;BR /&gt;
		);&lt;BR /&gt;
endcomp;&lt;BR /&gt;
&lt;BR /&gt;
however they don't want a straight average but a proportion based on two previous row_sum values.&lt;BR /&gt;
&lt;BR /&gt;
initially I thought can I lag the results from the previous two rows? I'd like to avoid going back into my main logic to calculate this.  Can I use a lag in a compute in proc report?</description>
      <pubDate>Mon, 05 Oct 2009 20:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/now-they-tell-me/m-p/74414#M21583</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-05T20:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: now they tell me</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/now-they-tell-me/m-p/74415#M21584</link>
      <description>Hi:&lt;BR /&gt;
  This documentation article outlines what you can put into a COMPUTE block. &lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a000146851.htm#a002473615" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a000146851.htm#a002473615&lt;/A&gt;&lt;BR /&gt;
And this Tech Support note shows an example of using the LAG function:&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/24/543.html" target="_blank"&gt;http://support.sas.com/kb/24/543.html&lt;/A&gt;&lt;BR /&gt;
                       &lt;BR /&gt;
although it shows the use of LAG within an IF statement, which has its own set of issues:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/etsug_tsdata_sect048.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/etsug_tsdata_sect048.htm&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/24/665.html" target="_blank"&gt;http://support.sas.com/kb/24/665.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/25/938.html" target="_blank"&gt;http://support.sas.com/kb/25/938.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/24/694.html" target="_blank"&gt;http://support.sas.com/kb/24/694.html&lt;/A&gt;&lt;BR /&gt;
                   &lt;BR /&gt;
Mostly, I avoid the use of the LAG function in PROC REPORT, because PROC REPORT is building one report row at a time, it really doesn't have visibility of the previous report rows when it's writing a new report row -- unless you save out the information into temporary variables. And, while the Data step program has a PDV (program data vector) from which it can retrieve and store lagged values, PROC REPORT does not have a PDV -- it only has some buffer areas where the summarized report information is held while the report rows are being written. &lt;BR /&gt;
                         &lt;BR /&gt;
It sounds like you have a fairly complicated PROC REPORT step. You may wish to work with Tech Support on this question, as they can look at your data and at your entire program and help you come up with the correct approach.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 06 Oct 2009 03:31:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/now-they-tell-me/m-p/74415#M21584</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-10-06T03:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: now they tell me</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/now-they-tell-me/m-p/74416#M21585</link>
      <description>any suggestions on how to best save a value into a temp value inside a compute block?</description>
      <pubDate>Tue, 06 Oct 2009 14:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/now-they-tell-me/m-p/74416#M21585</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-06T14:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: now they tell me</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/now-they-tell-me/m-p/74417#M21586</link>
      <description>Hi:&lt;BR /&gt;
  Here's an example that I had. It shows two things: there are a BUNCH of temporary variables and there's one COMPUTED variable (SILLYVAR). The difference between the two types of variables is outlined in a documentation topic entitled, "".&lt;BR /&gt;
 &lt;BR /&gt;
  This is a very simple example of how certain values were saved into temporary variables in a compute block and then used -- in this case, at the end of the report.  &lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
ods listing close;&lt;BR /&gt;
ods html file='c:\temp\use_temp_var.html' style=sasweb;&lt;BR /&gt;
proc report data=sashelp.class nowd&lt;BR /&gt;
  style(lines)={just=l};&lt;BR /&gt;
  title 'Example: Using Temporary Variables';&lt;BR /&gt;
  title2 'HT12, HT14, HOLD12, HOLD14, AV12, AV14, HOLDALL and HTALL are the temp variables';&lt;BR /&gt;
  title3 'SillyVar is a COMPUTED variable';&lt;BR /&gt;
  column age n  height weight sillyvar;&lt;BR /&gt;
  define age / group;&lt;BR /&gt;
  define n / 'Count';&lt;BR /&gt;
  define height / mean  'Avg Height';&lt;BR /&gt;
  define weight / mean 'Avg Weight';&lt;BR /&gt;
  define sillyvar / computed 'Silly Var';&lt;BR /&gt;
  compute sillyvar;&lt;BR /&gt;
     sillyvar = weight.mean - height.mean;&lt;BR /&gt;
  endcomp;&lt;BR /&gt;
  compute height;&lt;BR /&gt;
    if age = 12 then do; hold12 = n;	ht12 = height.mean; end;&lt;BR /&gt;
    else if age = 14 then do; hold14 = n; ht14 = height.mean; end;&lt;BR /&gt;
    if _break_ = '_RBREAK_' then do; holdall = n; htall = height.mean; end;&lt;BR /&gt;
  endcomp;&lt;BR /&gt;
  rbreak after / summarize;&lt;BR /&gt;
  compute after;&lt;BR /&gt;
    av12 = hold12 / holdall;&lt;BR /&gt;
    av14 = hold14 / holdall;&lt;BR /&gt;
    line 'Average Height for 12 year olds: ' ht12 4.1 ;&lt;BR /&gt;
    line 'This group is ' av12 percent8.2 'of all ages which represents' hold12 2.0 ' divided by ' holdall 2.0; &lt;BR /&gt;
    line ' ';&lt;BR /&gt;
    line 'Average Height for 14 year olds: ' ht14 4.1 ;&lt;BR /&gt;
    line 'This group is ' av14 percent8.2 'of all ages which represents' hold14 2.0 ' divided by ' holdall 2.0; &lt;BR /&gt;
    line ' ';&lt;BR /&gt;
    line 'The overall Average Height is: ' htall 4.1;&lt;BR /&gt;
  endcomp;&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 06 Oct 2009 16:38:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/now-they-tell-me/m-p/74417#M21586</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-10-06T16:38:40Z</dc:date>
    </item>
  </channel>
</rss>

