<?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: How do I vertically change value to the one above? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-vertically-change-value-to-the-one-above/m-p/792518#M253935</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

prev_var2 = lag(var2);

if var1=0 then var2=prev_var2;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302884"&gt;@niki0209&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking to change values of observations that satisfy a specific condition to the values "above".&lt;BR /&gt;My data looks somewhat like this:&lt;/P&gt;
&lt;P&gt;var1 var2&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;0 X&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;2 B&lt;BR /&gt;2 B&lt;BR /&gt;0 X&lt;BR /&gt;2 B&lt;BR /&gt;2 B&lt;BR /&gt;3 C&lt;BR /&gt;3 C&lt;BR /&gt;3 C&lt;BR /&gt;0 X&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example I would like to change the value of var2 to the value of the observation above, only if the value of var1 is equal to 0.&lt;/P&gt;
&lt;P&gt;In the example above, the result would be:&lt;/P&gt;
&lt;P&gt;var1 var2&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;0 A&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;2 B&lt;BR /&gt;2 B&lt;BR /&gt;0 B&lt;BR /&gt;2 B&lt;BR /&gt;2 B&lt;BR /&gt;3 C&lt;BR /&gt;3 C&lt;BR /&gt;3 C&lt;BR /&gt;0 C&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope someone can help me. Thanks alot!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jan 2022 16:10:53 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-01-26T16:10:53Z</dc:date>
    <item>
      <title>How do I vertically change value to the one above?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-vertically-change-value-to-the-one-above/m-p/792510#M253929</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking to change values of observations that satisfy a specific condition to the values "above".&lt;BR /&gt;My data looks somewhat like this:&lt;/P&gt;
&lt;P&gt;var1 var2&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;0 X&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;2 B&lt;BR /&gt;2 B&lt;BR /&gt;0 X&lt;BR /&gt;2 B&lt;BR /&gt;2 B&lt;BR /&gt;3 C&lt;BR /&gt;3 C&lt;BR /&gt;3 C&lt;BR /&gt;0 X&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example I would like to change the value of var2 to the value of the observation above, only if the value of var1 is equal to 0.&lt;/P&gt;
&lt;P&gt;In the example above, the result would be:&lt;/P&gt;
&lt;P&gt;var1 var2&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;0 A&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;2 B&lt;BR /&gt;2 B&lt;BR /&gt;0 B&lt;BR /&gt;2 B&lt;BR /&gt;2 B&lt;BR /&gt;3 C&lt;BR /&gt;3 C&lt;BR /&gt;3 C&lt;BR /&gt;0 C&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope someone can help me. Thanks alot!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 15:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-vertically-change-value-to-the-one-above/m-p/792510#M253929</guid>
      <dc:creator>niki0209</dc:creator>
      <dc:date>2022-01-26T15:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I vertically change value to the one above?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-vertically-change-value-to-the-one-above/m-p/792517#M253934</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input var1 var2 $;
cards;
1 A
1 A
1 A
0 X
1 A
1 A
2 B
2 B
0 X
2 B
2 B
3 C
3 C
3 C
0 X
;

data want;
 set have;
 k=lag(var2);
 if var1=0 then var2=k;
 drop k;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jan 2022 16:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-vertically-change-value-to-the-one-above/m-p/792517#M253934</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2022-01-26T16:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I vertically change value to the one above?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-vertically-change-value-to-the-one-above/m-p/792518#M253935</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

prev_var2 = lag(var2);

if var1=0 then var2=prev_var2;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302884"&gt;@niki0209&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking to change values of observations that satisfy a specific condition to the values "above".&lt;BR /&gt;My data looks somewhat like this:&lt;/P&gt;
&lt;P&gt;var1 var2&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;0 X&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;2 B&lt;BR /&gt;2 B&lt;BR /&gt;0 X&lt;BR /&gt;2 B&lt;BR /&gt;2 B&lt;BR /&gt;3 C&lt;BR /&gt;3 C&lt;BR /&gt;3 C&lt;BR /&gt;0 X&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example I would like to change the value of var2 to the value of the observation above, only if the value of var1 is equal to 0.&lt;/P&gt;
&lt;P&gt;In the example above, the result would be:&lt;/P&gt;
&lt;P&gt;var1 var2&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;0 A&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;2 B&lt;BR /&gt;2 B&lt;BR /&gt;0 B&lt;BR /&gt;2 B&lt;BR /&gt;2 B&lt;BR /&gt;3 C&lt;BR /&gt;3 C&lt;BR /&gt;3 C&lt;BR /&gt;0 C&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope someone can help me. Thanks alot!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 16:10:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-vertically-change-value-to-the-one-above/m-p/792518#M253935</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-26T16:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I vertically change value to the one above?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-vertically-change-value-to-the-one-above/m-p/792548#M253947</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302884"&gt;@niki0209&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   var2 = ifc(var1,var2,lag(var2));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 17:09:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-vertically-change-value-to-the-one-above/m-p/792548#M253947</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2022-01-26T17:09:11Z</dc:date>
    </item>
  </channel>
</rss>

