<?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: Finding the next value by group processing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562411#M157546</link>
    <description>&lt;P&gt;Good.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Wed, 29 May 2019 21:48:43 GMT</pubDate>
    <dc:creator>mansour_ib_sas</dc:creator>
    <dc:date>2019-05-29T21:48:43Z</dc:date>
    <item>
      <title>Finding the next value by group processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562279#M157499</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this data;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id $ val;
cards;
A .
A .
A .
A 5
A .
A 6
B .
B .
B .
B 4
B .
B .
B 7
; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want this result :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id $ val;
cards;
A 5
A 5
A 5
A 5
A 6
A 6
A 6
B 4
B 4
B 4
B 4
B 7
B 7
B 7
; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How i can get this result?&lt;/P&gt;&lt;P&gt;Thank you for your help&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 13:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562279#M157499</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2019-05-29T13:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the next value by group processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562281#M157500</link>
      <description>&lt;P&gt;I am not quite sure I understand. There are more observations in the second list than in the first one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you wanted to carry over the value of val for all missing entries until you get to a new value and then carry that value on until a new value etc you could use the RETAIN statement but it would require careful ordering of the data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Without another variable to distinguish the observation other than id it will be tricky to assign different values to the same id value.&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 14:04:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562281#M157500</guid>
      <dc:creator>33pedro</dc:creator>
      <dc:date>2019-05-29T14:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the next value by group processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562283#M157501</link>
      <description>&lt;P&gt;Here's one approach (assuming you fix the number of observations in your example):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until (last.id or val &amp;gt; .) ;
   set have;
   by id;
end;
replacement_val = val;
do until (last.id or val &amp;gt; .) ;
   set have;
   by id;
   output;
end;
drop val;
rename replacement_val = val;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The bottom loop reads the same observations as the top loop, but has an additional variable to work with as it outputs observations.&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 14:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562283#M157501</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-29T14:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the next value by group processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562299#M157507</link>
      <description>&lt;P&gt;Here's a different approach that only reads the input data once&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id $ val;
cards;
A .
A .
A .
A 5
A .
A 6
B .
B .
B .
B 4
B .
B .
B 7
; run;

data want ;
	retain cntr 0 ;
	set test ;
	cntr+1 ;
	if val ne . then do ;
		do i=1 to cntr ;
			output want ;
		end ;
		cntr=0 ;
	end ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It counts the number of observations that have a missing value, and then when it gets to an obs that has a value it writes to the output dataset, and resets the counter (cntr)&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 14:36:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562299#M157507</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2019-05-29T14:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the next value by group processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562302#M157509</link>
      <description>&lt;P&gt;thank you for your reply.&lt;BR /&gt;I can't visualize the process of treatment including the ability of the program to change the value of replacement_val at the right time.&lt;BR /&gt;I know that the condition (or val&amp;gt;.) Has a role.&lt;BR /&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 14:40:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562302#M157509</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2019-05-29T14:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the next value by group processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562308#M157514</link>
      <description>&lt;P&gt;Based on the presented data, looks like by-processing is not required, so your code could be reduced to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   do until (val &amp;gt; .) ;
      set have;
   end;

   replacement_val = val;

   do until (val &amp;gt; .) ;
      set have;
      output;
   end;

   drop val;
   rename replacement_val = val;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 14:56:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562308#M157514</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-05-29T14:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the next value by group processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562363#M157529</link>
      <description>&lt;P&gt;Here are some of the initial steps, to get you thinking about the process correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The top loop starts reading in observations.&amp;nbsp; It finds VAL is 5 on the fourth observation, so that's where the loop stops.&lt;/LI&gt;
&lt;LI&gt;SAS copies the value of 5 into REPLACEMENT_VAL.&lt;/LI&gt;
&lt;LI&gt;The bottom loop starts reading the same observations.&amp;nbsp; Each SET statement acts independently of other SET statements, so the bottom loop begins with the first observation, and finishes with the fourth observation (VAL=5).&lt;/LI&gt;
&lt;LI&gt;The bottom loop outputs those observations.&amp;nbsp; Because of the later DROP and RENAME statements, VAL is 5 on all those observations.&lt;/LI&gt;
&lt;LI&gt;The top loop begins again, reading the next set of observations.&amp;nbsp; The SET statement tracks which observations it has already read, and begins with the fifth observation until it finds another one with a nonmissing value for VAL.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;This version of the program never copies VAL from the previous ID.&amp;nbsp; It always begins again when it finds a new ID.&amp;nbsp; I assumed that's what you wanted, but could be wrong about that.&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 17:35:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562363#M157529</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-29T17:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the next value by group processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562411#M157546</link>
      <description>&lt;P&gt;Good.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 21:48:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-next-value-by-group-processing/m-p/562411#M157546</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2019-05-29T21:48:43Z</dc:date>
    </item>
  </channel>
</rss>

