<?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 Replace value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336873#M76417</link>
    <description>&lt;P&gt;data have;&lt;BR /&gt;input id ntime week time;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 1 0&lt;BR /&gt;1 0 4 718&lt;BR /&gt;1 0 4 718&lt;BR /&gt;1 2 4 720&lt;BR /&gt;1 2 4 720&lt;BR /&gt;1 0 12 .&lt;BR /&gt;1 0 12 .&lt;BR /&gt;1 2 12 1748&lt;BR /&gt;1 2 12 1748&lt;BR /&gt;;;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;input id ntime week time;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 1 0&lt;BR /&gt;1 0 4 718&lt;BR /&gt;1 0 4 718&lt;BR /&gt;1 2 4 718&lt;BR /&gt;1 2 4 720&lt;BR /&gt;1 0 12 .&lt;BR /&gt;1 0 12 .&lt;BR /&gt;1 2 12 .&lt;BR /&gt;1 2 12 1748&lt;/P&gt;&lt;P&gt;;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to replace the first value at ntime=2 &amp;amp; week=4 with the value from ntime=0 &amp;amp; week=4&lt;/P&gt;&lt;P&gt;similarly. replace the first value at ntime=2 &amp;amp; week=12 with the value from ntime=0 &amp;amp; week=12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas to to get want datset?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
    <pubDate>Wed, 01 Mar 2017 09:52:49 GMT</pubDate>
    <dc:creator>ari</dc:creator>
    <dc:date>2017-03-01T09:52:49Z</dc:date>
    <item>
      <title>Replace value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336873#M76417</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input id ntime week time;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 1 0&lt;BR /&gt;1 0 4 718&lt;BR /&gt;1 0 4 718&lt;BR /&gt;1 2 4 720&lt;BR /&gt;1 2 4 720&lt;BR /&gt;1 0 12 .&lt;BR /&gt;1 0 12 .&lt;BR /&gt;1 2 12 1748&lt;BR /&gt;1 2 12 1748&lt;BR /&gt;;;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;input id ntime week time;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 1 0&lt;BR /&gt;1 0 4 718&lt;BR /&gt;1 0 4 718&lt;BR /&gt;1 2 4 718&lt;BR /&gt;1 2 4 720&lt;BR /&gt;1 0 12 .&lt;BR /&gt;1 0 12 .&lt;BR /&gt;1 2 12 .&lt;BR /&gt;1 2 12 1748&lt;/P&gt;&lt;P&gt;;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to replace the first value at ntime=2 &amp;amp; week=4 with the value from ntime=0 &amp;amp; week=4&lt;/P&gt;&lt;P&gt;similarly. replace the first value at ntime=2 &amp;amp; week=12 with the value from ntime=0 &amp;amp; week=12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas to to get want datset?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 09:52:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336873#M76417</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2017-03-01T09:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: Replace value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336877#M76419</link>
      <description>&lt;P&gt;The value from ntime = 0 &amp;amp; week = 4 is 718.&lt;/P&gt;
&lt;P&gt;Why is the first value for ntime = 2 and week = 12 set to missing?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 09:29:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336877#M76419</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-01T09:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: Replace value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336882#M76420</link>
      <description>&lt;P&gt;Well, odd request, doesn't seem much logic in it? &amp;nbsp;Anyways the want you gave does not match the logic you give to get it. &amp;nbsp;This code matches the logic you have given in your text:&lt;/P&gt;
&lt;PRE&gt;data have;
  input id ntime week time;
datalines;
1 0 1 0
1 0 4 718
1 0 4 718
1 2 4 720
1 2 4 720
1 0 12 .
1 0 12 .
1 2 12 1748
1 2 12 1748
;
run;

proc sql;
  create table WANT as 
  select  *,
          (select distinct TIME from HAVE where NTIME=0 and WEEK=4) as REP
  from    HAVE;
quit;

data want;
  set want;
  by id ntime notsorted;
  if first.ntime and ntime=2 then time=rep;
run;&lt;/PRE&gt;
&lt;P&gt;But you will see that 2/12 does not match as "." is not at 0/4, 718 is.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 09:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336882#M76420</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-01T09:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Replace value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336892#M76423</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There was a mistake in the text. i have edited it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 09:54:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336892#M76423</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2017-03-01T09:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Replace value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336893#M76424</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;: Thanks but this is not what I wanted. I have updated the text. there was a mistake.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 09:58:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336893#M76424</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2017-03-01T09:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: Replace value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336896#M76425</link>
      <description>&lt;P&gt;You can change my original code per your update to the logic:&lt;/P&gt;
&lt;PRE&gt;data have;
  input id ntime week time;
datalines;
1 0 1 0
1 0 4 718
1 0 4 718
1 2 4 720
1 2 4 720
1 0 12 .
1 0 12 .
1 2 12 1748
1 2 12 1748
;
run;

proc sql;
  create table WANT as 
  select  *,
          (select distinct TIME from HAVE where NTIME=0 and WEEK=4) as REP1,
          (select distinct TIME from HAVE where NTIME=0 and WEEK=12) as REP2
  from    HAVE;
quit;

data want;
  set want;
  by id ntime notsorted;
  if first.ntime and ntime=2 and week=4 then time=rep1;
  if first.ntime and ntime=2 and week=12 then time=rep2;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Mar 2017 10:01:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336896#M76425</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-01T10:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: Replace value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336899#M76427</link>
      <description>&lt;P&gt;Then my code suggestion looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id ntime week time;
datalines;
1 0 1 0
1 0 4 718
1 0 4 718
1 2 4 720
1 2 4 720
1 0 12 .
1 0 12 .
1 2 12 1748
1 2 12 1748
;
run;

data want;
set have;
by id week; /* this is only to guarantee a correct order */
retain keepval flag;
if ntime = 0
then do;
  keepval = time;
  flag = 1;
end;
if ntime = 2 and flag
then do;
  time = keepval;
  flag = 0;
end;
drop keepval flag;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs    id    ntime    week    time

 1      1      0        1        0
 2      1      0        4      718
 3      1      0        4      718
 4      1      2        4      718
 5      1      2        4      720
 6      1      0       12        .
 7      1      0       12        .
 8      1      2       12        .
 9      1      2       12     1748
&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Mar 2017 10:07:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336899#M76427</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-01T10:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: Replace value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336914#M76433</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;: Perfect, Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 10:45:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336914#M76433</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2017-03-01T10:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: Replace value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336915#M76434</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;: Perfect, thanks&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 10:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-value/m-p/336915#M76434</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2017-03-01T10:46:01Z</dc:date>
    </item>
  </channel>
</rss>

