<?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 Retain and by group processing in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Retain-and-by-group-processing/m-p/29589#M6949</link>
    <description>My data looks like this:&lt;BR /&gt;
&lt;BR /&gt;
Obs	change	Md_mg	M_mg&lt;BR /&gt;
1	0	0	8.7912&lt;BR /&gt;
2	1	0.00232	.&lt;BR /&gt;
3	2	0.00304	.&lt;BR /&gt;
4	3	0.0032	.&lt;BR /&gt;
5	4	0.00304	.&lt;BR /&gt;
6	5	0.00784	.&lt;BR /&gt;
7	6	0.0248	.&lt;BR /&gt;
8	7	0.0328	.&lt;BR /&gt;
9	8	0.044	.&lt;BR /&gt;
10	9	0.0224	.&lt;BR /&gt;
11	10	0.0312	.&lt;BR /&gt;
12	11	0.028	.&lt;BR /&gt;
13	12	0.0328	.&lt;BR /&gt;
14	13	0.0256	.&lt;BR /&gt;
15	14	0.028	.&lt;BR /&gt;
16	0	0	8.8992&lt;BR /&gt;
17	1	0.00248	.&lt;BR /&gt;
18	2	0.00288	.&lt;BR /&gt;
19	3	0.00304	.&lt;BR /&gt;
20	4	0.00312	.&lt;BR /&gt;
21	5	0.00776	.&lt;BR /&gt;
22	6	0.0216	.&lt;BR /&gt;
23	7	0.0328	.&lt;BR /&gt;
24	8	0.0448	.&lt;BR /&gt;
25	9	0.0224	.&lt;BR /&gt;
26	10	0.036	.&lt;BR /&gt;
27	11	0.0312	.&lt;BR /&gt;
28	12	0.0336	.&lt;BR /&gt;
29	13	0.028	.&lt;BR /&gt;
30	14	0.0264	.&lt;BR /&gt;
&lt;BR /&gt;
I *simply* want to fill in the missing values for M_mg in a check book balancing type of process, subtracting Md_mg each time; in other words for observation 2 M_mg should equal 8.78888, for observation 3 it should equal 8.78584, and so on.  Resetting at the change variable 0 (0 is first.).&lt;BR /&gt;
&lt;BR /&gt;
I've tried various combinations of the retain statement, first., etc. and appear to be stuck.  Help appreciated!  Thank you. NWV</description>
    <pubDate>Fri, 08 May 2009 13:51:12 GMT</pubDate>
    <dc:creator>NWV</dc:creator>
    <dc:date>2009-05-08T13:51:12Z</dc:date>
    <item>
      <title>Retain and by group processing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-and-by-group-processing/m-p/29589#M6949</link>
      <description>My data looks like this:&lt;BR /&gt;
&lt;BR /&gt;
Obs	change	Md_mg	M_mg&lt;BR /&gt;
1	0	0	8.7912&lt;BR /&gt;
2	1	0.00232	.&lt;BR /&gt;
3	2	0.00304	.&lt;BR /&gt;
4	3	0.0032	.&lt;BR /&gt;
5	4	0.00304	.&lt;BR /&gt;
6	5	0.00784	.&lt;BR /&gt;
7	6	0.0248	.&lt;BR /&gt;
8	7	0.0328	.&lt;BR /&gt;
9	8	0.044	.&lt;BR /&gt;
10	9	0.0224	.&lt;BR /&gt;
11	10	0.0312	.&lt;BR /&gt;
12	11	0.028	.&lt;BR /&gt;
13	12	0.0328	.&lt;BR /&gt;
14	13	0.0256	.&lt;BR /&gt;
15	14	0.028	.&lt;BR /&gt;
16	0	0	8.8992&lt;BR /&gt;
17	1	0.00248	.&lt;BR /&gt;
18	2	0.00288	.&lt;BR /&gt;
19	3	0.00304	.&lt;BR /&gt;
20	4	0.00312	.&lt;BR /&gt;
21	5	0.00776	.&lt;BR /&gt;
22	6	0.0216	.&lt;BR /&gt;
23	7	0.0328	.&lt;BR /&gt;
24	8	0.0448	.&lt;BR /&gt;
25	9	0.0224	.&lt;BR /&gt;
26	10	0.036	.&lt;BR /&gt;
27	11	0.0312	.&lt;BR /&gt;
28	12	0.0336	.&lt;BR /&gt;
29	13	0.028	.&lt;BR /&gt;
30	14	0.0264	.&lt;BR /&gt;
&lt;BR /&gt;
I *simply* want to fill in the missing values for M_mg in a check book balancing type of process, subtracting Md_mg each time; in other words for observation 2 M_mg should equal 8.78888, for observation 3 it should equal 8.78584, and so on.  Resetting at the change variable 0 (0 is first.).&lt;BR /&gt;
&lt;BR /&gt;
I've tried various combinations of the retain statement, first., etc. and appear to be stuck.  Help appreciated!  Thank you. NWV</description>
      <pubDate>Fri, 08 May 2009 13:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-and-by-group-processing/m-p/29589#M6949</guid>
      <dc:creator>NWV</dc:creator>
      <dc:date>2009-05-08T13:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: Retain and by group processing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-and-by-group-processing/m-p/29590#M6950</link>
      <description>[pre]&lt;BR /&gt;
data change;&lt;BR /&gt;
   input Obs change Md_mg M_mg0;&lt;BR /&gt;
   if change eq 0 then M_mg = m_mg0;&lt;BR /&gt;
   else m_mg = m_mg - md_mg;&lt;BR /&gt;
   retain m_mg;&lt;BR /&gt;
   cards;&lt;BR /&gt;
1 0 0 8.7912&lt;BR /&gt;
2 1 0.00232 .&lt;BR /&gt;
3 2 0.00304 .&lt;BR /&gt;
4 3 0.0032 .&lt;BR /&gt;
5 4 0.00304 .&lt;BR /&gt;
6 5 0.00784 .&lt;BR /&gt;
7 6 0.0248 .&lt;BR /&gt;
8 7 0.0328 .&lt;BR /&gt;
9 8 0.044 .&lt;BR /&gt;
10 9 0.0224 .&lt;BR /&gt;
11 10 0.0312 .&lt;BR /&gt;
12 11 0.028 .&lt;BR /&gt;
13 12 0.0328 .&lt;BR /&gt;
14 13 0.0256 .&lt;BR /&gt;
15 14 0.028 .&lt;BR /&gt;
16 0 0 8.8992&lt;BR /&gt;
17 1 0.00248 .&lt;BR /&gt;
18 2 0.00288 .&lt;BR /&gt;
19 3 0.00304 .&lt;BR /&gt;
20 4 0.00312 .&lt;BR /&gt;
21 5 0.00776 .&lt;BR /&gt;
22 6 0.0216 .&lt;BR /&gt;
23 7 0.0328 .&lt;BR /&gt;
24 8 0.0448 .&lt;BR /&gt;
25 9 0.0224 .&lt;BR /&gt;
26 10 0.036 .&lt;BR /&gt;
27 11 0.0312 .&lt;BR /&gt;
28 12 0.0336 .&lt;BR /&gt;
29 13 0.028 .&lt;BR /&gt;
30 14 0.0264 .&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 08 May 2009 14:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-and-by-group-processing/m-p/29590#M6950</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-05-08T14:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Retain and by group processing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-and-by-group-processing/m-p/29591#M6951</link>
      <description>Thank you.  &lt;BR /&gt;
&lt;BR /&gt;
I use your suggestion and ended up doing something similar, although I did use the first. instead of if change=0.&lt;BR /&gt;
&lt;BR /&gt;
I have another variable sampletype that uniquely codes the groups, so with first.sampletype=m_mg0 (now called T0_mass), I then retained the m_mg and subtracted md_mg--the code looked like this and produced the needed result:&lt;BR /&gt;
&lt;BR /&gt;
data d4;&lt;BR /&gt;
set d3;&lt;BR /&gt;
by sample change;&lt;BR /&gt;
retain M_mg;&lt;BR /&gt;
if first.sample then M_mg=T0_mass;&lt;BR /&gt;
M_mg=M_mg-Md_mg;&lt;BR /&gt;
proc print data=d4;run;&lt;BR /&gt;
&lt;BR /&gt;
Thank you again for the clue the provided my solution.</description>
      <pubDate>Fri, 08 May 2009 14:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-and-by-group-processing/m-p/29591#M6951</guid>
      <dc:creator>NWV</dc:creator>
      <dc:date>2009-05-08T14:40:30Z</dc:date>
    </item>
  </channel>
</rss>

