<?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: Conditional copy value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/518034#M140153</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID   var1 $ var2 ;
cards;
111 aaa   100
111 aaa   101
111   .       102
111    .       .
222 bbb  101
222 bbb  102
222    .     103
;

data want;
 set have;
 length new_var1 $ 80;
 retain new_var1 new_var2;
 by id;
 if first.id then call missing(new_var1,new_var2);
 if not missing(var1) then new_var1=var1;
 if not missing(var2) then new_var2=var2;
 if cmiss(new_var1,new_var2)=2 then call missing(new_var1,new_var2);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 03 Dec 2018 12:41:46 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-12-03T12:41:46Z</dc:date>
    <item>
      <title>Conditional copy value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/517819#M140063</link>
      <description>&lt;P&gt;Hi, there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my data looks like this:&lt;BR /&gt;ID&amp;nbsp; &amp;nbsp;var1&amp;nbsp; var2&lt;BR /&gt;111 aaa&amp;nbsp; &amp;nbsp;100&lt;BR /&gt;111 aaa&amp;nbsp; &amp;nbsp;101&lt;BR /&gt;111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 102&lt;/P&gt;&lt;P&gt;111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;222 bbb&amp;nbsp; 101&lt;BR /&gt;222 bbb&amp;nbsp; 102&lt;BR /&gt;222&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;103&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Just curious how can I fill the null var1 with previous row's value ony if var2 is not null and the desired data looks like:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;want&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;ID&amp;nbsp; &amp;nbsp;var1 var2&lt;BR /&gt;111 aaa&amp;nbsp; 100&lt;BR /&gt;111 aaa&amp;nbsp; 101&lt;BR /&gt;111 aaa&amp;nbsp; 102&lt;/P&gt;&lt;P&gt;111&lt;BR /&gt;222 bbb&amp;nbsp; 101&lt;BR /&gt;222 bbb&amp;nbsp; 102&lt;BR /&gt;222 bbb&amp;nbsp; 102&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Sun, 02 Dec 2018 06:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/517819#M140063</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-12-02T06:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional copy value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/517828#M140065</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID   var1 $ var2 ;
cards;
111 aaa   100
111 aaa   101
111   .       102
111    .       .
222 bbb  101
222 bbb  102
222    .     103
;

data want;
set have;
by id;
k=lag(var1);
if not first.id and missing(var1) and k&amp;gt;' ' and var2 then var1=k;
drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Dec 2018 06:41:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/517828#M140065</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-02T06:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional copy value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/517886#M140090</link>
      <description>&lt;P&gt;What if you have consecutive instances of missing var1&amp;nbsp; but non-missing var2?&amp;nbsp;&amp;nbsp; I.e. what if you have&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID   var1 $ var2 ;
cards;
111 aaa   100
111 aaa   101
111   .       102
111   .       103
111    .       .
222 bbb  101
222 bbb  102
222    .     103
;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Dec 2018 17:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/517886#M140090</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-12-02T17:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional copy value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/517952#M140106</link>
      <description>&lt;P&gt;I will only copy var1 when var 2 is not missing. missing var 1 is not irrelevant&amp;nbsp;in this case, thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 03:11:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/517952#M140106</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-12-03T03:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional copy value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/517955#M140109</link>
      <description>&lt;P&gt;What have you tried? Can you show your sincere attempt? I have noticed you haven't showed either in any of your threads and I think that's unfair&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 03:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/517955#M140109</guid>
      <dc:creator>Allaluiah</dc:creator>
      <dc:date>2018-12-03T03:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional copy value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/517981#M140132</link>
      <description>&lt;P&gt;Try this.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set sample;
var1=ifc ((var1="" and var2&amp;gt;0),lag(var1),var1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Dec 2018 08:03:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/517981#M140132</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2018-12-03T08:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional copy value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/518034#M140153</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID   var1 $ var2 ;
cards;
111 aaa   100
111 aaa   101
111   .       102
111    .       .
222 bbb  101
222 bbb  102
222    .     103
;

data want;
 set have;
 length new_var1 $ 80;
 retain new_var1 new_var2;
 by id;
 if first.id then call missing(new_var1,new_var2);
 if not missing(var1) then new_var1=var1;
 if not missing(var2) then new_var2=var2;
 if cmiss(new_var1,new_var2)=2 then call missing(new_var1,new_var2);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Dec 2018 12:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-copy-value/m-p/518034#M140153</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-12-03T12:41:46Z</dc:date>
    </item>
  </channel>
</rss>

