<?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: Fill down the data when condition changes within id in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Fill-down-the-data-when-condition-changes-within-id/m-p/646724#M193494</link>
    <description>&lt;P&gt;Retain the new variable, and set it with proper conditions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by id;
retain side;
_loc = lag(loc);
if first.id
then side = "-";
else do;
  if side = "U" and loc ne _loc then side = "B";
  if side = "-" and loc ne "" then side = "U";
end;
drop _loc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 May 2020 14:36:56 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-05-11T14:36:56Z</dc:date>
    <item>
      <title>Fill down the data when condition changes within id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-down-the-data-when-condition-changes-within-id/m-p/646714#M193491</link>
      <description>&lt;P&gt;&lt;FONT face="times new roman,times" size="4"&gt;Dear All,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="times new roman,times" size="4"&gt;I am struggling to work this out and hoping if anyone could help me on this please?&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="times new roman,times" size="4"&gt;That is, when loc has either changed from left to right or changed from right to left, side will B and remains B throughout the end.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="times new roman,times" size="4"&gt;In fact, I have used this dummy data for another question of mine yesterday &lt;LI-MESSAGE title="flag and count by id when condition is met" uid="646400" url="https://communities.sas.com/t5/SAS-Programming/flag-and-count-by-id-when-condition-is-met/m-p/646400#U646400" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;and was solved by Shmuel.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="times new roman,times" size="4"&gt;I tried to tweak Shmuel's code but sadly no success.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="times new roman,times" size="4"&gt;Thanking you in advance.&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id vis test  loc   side   
1	0			   -     
1	1	1	Left   U   	
1	1	1	Right  B    	
1	2	1	Left   B   	
1	2	0	Right  B    	
1	3	0	Left   B   	
1	3	0	Right  B    	
1	4	1	Left   B   	
1	5	1	Left   B   	
1	6	0		   B     
1	7	0		   B     
1	8	1	Left   B   	
1	8	1	Left   B   	
1	8	1	Right  B    	
1	9	0		   B     
1	9	0	Right  B    	
1	10	0		   B     
1	11	1	Left   B   	
1	12	1	Left   B   	
1	13	0		   B     
1	13	1	Right  B    	
1	14	0		   B     
1	14	1	Right  B    	
1	15	0	Left   B   	
1	15	0	Right  B    	
1	16	0	Left   B   	
2	0			   -     
2	1	1	Left   U   	
2	2	1	Left   U   	
2	3	1	Left   U   	
2	3	1	Right  B    	
2	4	0		   B     
2	4	1	Right  B    	
2	4	1	Right  B    	
2	5	0		   B     
2	6	1	Left   B   	
2	6	1	Right  B    	
2	7	1	Left   B   	
2	7	1	Right  B    	
2	8	0	Left   B   	
2	8	0	Right  B    	
2	9	1	Left   B   	
2	10	1	Left   B   	
2	11	1	Left   B   	
2	12	1	Left   B   	
2	12	1	Right  B    	
2	13	0	Left   B   	
2	13	1	Right  B    	
2	14	0	Left   B   	
2	14	0	Right  B    	
2	15	0	Left   B   	
2	16	0	Left   B   	
2	17	1	Left   B   	
2	18	0	Left   B   	
2	18	1	Right  B    	
2	19	1	Left   B   	
2	19	0	Right  B    	
2	20	1	Left   B   	
2	20	0	Right  B    	
2	21	1	Left   B   	
2	21	0	Right  B    	
2	22	0	Left   B   	
2	22	1	Right  B    	
2	23	0		   B     
2	24	0	Left   B   	
2	24	1	Right  B    	
2	25	0	Left   B   	
2	25	1	Right  B    	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 May 2020 14:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-down-the-data-when-condition-changes-within-id/m-p/646714#M193491</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2020-05-11T14:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Fill down the data when condition changes within id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-down-the-data-when-condition-changes-within-id/m-p/646724#M193494</link>
      <description>&lt;P&gt;Retain the new variable, and set it with proper conditions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by id;
retain side;
_loc = lag(loc);
if first.id
then side = "-";
else do;
  if side = "U" and loc ne _loc then side = "B";
  if side = "-" and loc ne "" then side = "U";
end;
drop _loc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 May 2020 14:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-down-the-data-when-condition-changes-within-id/m-p/646724#M193494</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-11T14:36:56Z</dc:date>
    </item>
  </channel>
</rss>

