<?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 how to keep values in the following years once specified? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-keep-values-in-the-following-years-once-specified/m-p/829514#M327743</link>
    <description>&lt;P&gt;Hi everyone &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I make a simple example what I want to make&lt;/P&gt;&lt;P&gt;I have a dataset like...&lt;/P&gt;&lt;P&gt;ID Year&amp;nbsp; &amp;nbsp;V1 V2&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 2002&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2000&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2001&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2002&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;3&amp;nbsp; 2005&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;3&amp;nbsp; 2006&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;3&amp;nbsp; 2007&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to do is to create V2s equal to 1 if V1s grouped by ID and Year hit 1, or 0 otherwise + if V2 is first set as 1 then V2s in the subsequent years become 1 as well regardless of the value of V1s.&amp;nbsp; &amp;lt;---this is a tricky part. As shown below, I want to keep V2 in the following years after V2s are set as 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am doing is to make this... there is a threshold and if an observation hits this threshold then this observation is specified as something after all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I owe a lot to this community and appreciate your help tremendously!&amp;nbsp; &amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Year&amp;nbsp; &amp;nbsp;V1 V2&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 2002&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2000&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2001&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;2&amp;nbsp; 2002&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; 2005&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;3&amp;nbsp; 2006&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;3&amp;nbsp; 2007&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 20 Aug 2022 17:47:58 GMT</pubDate>
    <dc:creator>JKCho</dc:creator>
    <dc:date>2022-08-20T17:47:58Z</dc:date>
    <item>
      <title>how to keep values in the following years once specified?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-keep-values-in-the-following-years-once-specified/m-p/829514#M327743</link>
      <description>&lt;P&gt;Hi everyone &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I make a simple example what I want to make&lt;/P&gt;&lt;P&gt;I have a dataset like...&lt;/P&gt;&lt;P&gt;ID Year&amp;nbsp; &amp;nbsp;V1 V2&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 2002&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2000&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2001&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2002&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;3&amp;nbsp; 2005&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;3&amp;nbsp; 2006&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;3&amp;nbsp; 2007&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to do is to create V2s equal to 1 if V1s grouped by ID and Year hit 1, or 0 otherwise + if V2 is first set as 1 then V2s in the subsequent years become 1 as well regardless of the value of V1s.&amp;nbsp; &amp;lt;---this is a tricky part. As shown below, I want to keep V2 in the following years after V2s are set as 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am doing is to make this... there is a threshold and if an observation hits this threshold then this observation is specified as something after all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I owe a lot to this community and appreciate your help tremendously!&amp;nbsp; &amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Year&amp;nbsp; &amp;nbsp;V1 V2&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 2002&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2000&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 2001&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;2&amp;nbsp; 2002&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; 2005&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;3&amp;nbsp; 2006&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;3&amp;nbsp; 2007&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2022 17:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-keep-values-in-the-following-years-once-specified/m-p/829514#M327743</guid>
      <dc:creator>JKCho</dc:creator>
      <dc:date>2022-08-20T17:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert values in a column if this value hits a certain threshold</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-keep-values-in-the-following-years-once-specified/m-p/829515#M327744</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Year V1;
datalines;
1 2002 0
2 2000 0
2 2001 1
2 2002 0
3 2005 0
3 2006 1
3 2007 1
;

data want;
   set have;
   by ID;
   if first.ID then V2 = 0;
   if V1 then V2 = 1;
   retain V2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID  Year  V1  V2
1   2002  0   0
2   2000  0   0
2   2001  1   1
2   2002  0   1
3   2005  0   0
3   2006  1   1
3   2007  1   1&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2022 17:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-keep-values-in-the-following-years-once-specified/m-p/829515#M327744</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-20T17:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to keep values in the following years once specified?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-keep-values-in-the-following-years-once-specified/m-p/829516#M327745</link>
      <description>&lt;P&gt;A simple application of retaining a variable.&lt;/P&gt;
&lt;P&gt;Note that the variable cannot be on the input (otherwise the retained value is replaced when the next record is read by the SET statement).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input ID Year V1 ;
cards;
1 2002 0
2 2000 0
2 2001 1
2 2002 0
3 2005 0
3 2006 1
3 2007 1
;

data want;
 set have;
 by id year ;
 if first.id then v2=v1;
 v2=max(v2,v1);
 retain v2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    ID    Year    V1    v2

 1      1    2002     0     0
 2      2    2000     0     0
 3      2    2001     1     1
 4      2    2002     0     1
 5      3    2005     0     0
 6      3    2006     1     1
 7      3    2007     1     1
&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Aug 2022 17:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-keep-values-in-the-following-years-once-specified/m-p/829516#M327745</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-20T17:50:17Z</dc:date>
    </item>
  </channel>
</rss>

